2015年百度之星初赛(1) --- A 超级赛亚ACMer
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:\n",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:\n",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; } /* */
作者:北岛知寒
出处:https://www.cnblogs.com/crazyacking/p/4540704.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
标签:
2015年百度之星初赛(1)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
2014-05-30 查找 --- 哈希优化
2014-05-30 SPFA + 链式前向星(详解)