超级赛亚ACMer
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5246
Mean:
略
analyse:
贪心,但是要注意策略。把所有人战力排个序,每次贪心的取能取到的最大的能激发潜力的人。
Time complexity: O(n)
Source code:
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-05-30-18.59 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; const int MAXN=10010; LL a[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int Cas,t; scanf("%d",&t); for(int Cas=1;Cas<=t;++Cas) { LL n,m,k; scanf("%lld %lld %lld",&n,&m,&k); for(int i=0;i<n;++i) scanf("%lld",&a[i]); printf("Case #%d: ",Cas); sort(a,a+n); if(a[0]>m) puts("madan!"); else if(a[n-1]<=m) puts("why am I so diao?"); else { int sta=0; for(int i=0;i<n;++i) { if(a[i]>m) { sta=i-1;break; } } LL now=a[sta]; LL nextPos=sta+1; while(nextPos<n) { if(now+k<a[nextPos]) { puts("madan!");break; } else { if(now+k>=a[n-1]) { puts("why am I so diao?");break; }else{ now=a[nextPos];k--;nextPos++; } } } } } return 0; } /* */
更容易理解的代码:
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-05-31-12.56 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; const int MAXN=10005; LL a[MAXN]; int main() { // freopen("C:\Users\crazyacking\Desktop\cin.txt","r",stdin); // freopen("C:\Users\crazyacking\Desktop\cout.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); int t; scanf("%d",&t); for(int Cas=1;Cas<=t;++Cas) { int n,m,k; scanf("%d %d %d",&n,&m,&k); for(int i=0;i<n;++i) scanf("%lld",&a[i]); sort(a,a+n); printf("Case #%d: ",Cas); if(m>=a[n-1]) puts("why am I so diao?"); else if(m<a[0]) puts("madan!"); else { int staPos=0; for(int i=0;i<n;++i) { if(a[i]>m) { staPos=i-1; break; } } LL now=a[staPos]; int nextPos=staPos+1; while(nextPos<n) { if(now+k<a[nextPos]) { puts("madan!"); break; } else { if(now+k>=a[n-1]) { puts("why am I so diao?"); break; } if(now>a[nextPos]) { nextPos++; continue; } if(now+k>=a[nextPos]) { now=a[nextPos]; nextPos++; k--; } } } } } return 0; } /* */