标签:names pac color name multi asc can oms multiple
3 6 100 100 100 99 98 101 6 100 100 100 99 99 101 6 100 100 98 99 99 97Sample Output
Case #1: 10000 Case #2: Bad Mushroom Case #3: 9999 10000
这个题实际就是hash查找,单他竟然卡了cin,应该是数据加强了,或者我的算法不是很好
#include <bits/stdc++.h> using namespace std; int cnt[10005]; int main() { int T,k=1; scanf("%d",&T); while(T--){ memset(cnt,0,sizeof(cnt)); int n;scanf("%d",&n); for(int i=0;i<n;i++){ int x;scanf("%d",&x); cnt[10000-(100-x)*(100-x)]++; } int ma=INT_MIN; for(int i=0;i<=10000;i++) ma=max(cnt[i],ma); int f=0; for(int i=0;i<=10000;i++) if(cnt[i]&&cnt[i]<ma){ f=1;break; } printf("Case #%d:\n",k++); if(ma<n&&!f)printf("Bad Mushroom\n"); else{ int f1=0; for(int i=0;i<=10000;i++){ if(cnt[i]==ma){ if(f1)printf(" "); printf("%d",i); f1=1; } } printf("\n"); } } return 0; }
InputThe first line contains only one integer T, which indicates the number of test cases.
For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9).
And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.OutputFor each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.Sample Input
2 1 10 5 5 2 10 3 3 6
Sample Output
Case #1: 2 Case #2: 4
贪心下就可以了
#include <bits/stdc++.h> using namespace std; const int N=1000010; int a[N]; int main() { int t,n,m,l,k=1; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&l); for(int i=0; i<n; i++) scanf("%d",&a[i]); sort(a,a+n); int fr=0,ans=0,pre=-l,now; a[n]=m; for (int i=0; i <=n; i++) { now=a[i]; int t2=(now-fr)/(l + 1); pre+=t2*(l + 1); ans+=t2*2; if (now-pre>l) { pre=fr+t2*(l+1); fr=now; ans++; } else fr=now; } printf("Case #%d: %d\n",k++,ans); } return 0; }
2014 ACM/ICPC Asia Regional 北京 Online
标签:names pac color name multi asc can oms multiple
原文地址:http://www.cnblogs.com/BobHuang/p/7254037.html