codeforce322笔记

来源:互联网 发布:特征提取算法 编辑:程序博客网 时间:2024/06/05 10:03


第三题

http://codeforces.com/contest/581/problem/C

1.要考虑到对100的处理和一轮循环后k大于10的情况

2.使用python的list存储 若k极大而每个值极小,则要做许多循环。因此应用dict存储相同值,减少重复操作 

3.考虑好边界的判断


纪念我shit一般的代码和思维…………      

      

      line1 = raw_input().strip().split(' ')      line2 = raw_input().strip().split(' ')      n,k = int(line1[0]),int(line1[1])       d = {}      cnt = 0      for x in range(n):            cnt += int(line2[x])/10                        if int(line2[x]) == 100:                  continue            xx = 10 - int(line2[x])%10            if xx in d:                  d[xx] += 1            else:                  d[xx] = 1      l = sorted(d.iteritems())      #print l      ll = []      for x in l:            ll.append([x[0],x[1]])      for x in ll:            while(x[1] > 0 and k >= x[0]):                  k -= x[0]                  x[1] -= 1                  cnt += 1            if k < x[0]:                  break      #print ll,k,cnt                        while k >= 10 and cnt < n * 10:            k -= 10            cnt += 1      print cnt      
    int n,k;    scanf("%d%d",&n,&k);    int i,x,cnt;    cnt = 0;    int a[10] = {0};    for(i = 0 ; i < n ; i++){        scanf("%d",&x);        cnt += x/10;        a[10-x%10] += 1;    }            for(i = 1; i <= 9 ;i ++){        while(a[i] > 0 && k >= i){            k -= i;            a[i] -= 1;            cnt += 1;                  }    }        while(k >= 10 && cnt < n *10){        k -= 10;        cnt += 1;    }        printf("%d",cnt);



最后是一段巧妙的代码

#include<stdio.h>int n,k,s;int a[11];int main(){scanf("%d%d",&n,&k);int temp,m=0;for(int i=-1;++i<n;s+=temp/10){scanf("%d",&temp);if(m=temp%10) a[10-m]++;a[10]+=(100-temp)/10;}for(int i=0;++i<=10;s+=temp){if((temp=a[i]*i)>k) temp=k;temp/=i;k-=temp*i;}printf("%d",s);} 


0 0
原创粉丝点击