算法竞赛入门经典训练指南-做题详细记录(更新中)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了算法竞赛入门经典训练指南-做题详细记录(更新中),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2228字,纯文字阅读大概需要4分钟。
内容图文
![算法竞赛入门经典训练指南-做题详细记录(更新中)](/upload/InfoBanner/zyjiaocheng/755/0f92d8c825194439b07eafd969d9a067.jpg)
第一章
![算法竞赛入门经典训练指南-做题详细记录(更新中) - 文章图片](/upload/getfiles/0001/2021/5/4/20210504042525909.jpg)
![算法竞赛入门经典训练指南-做题详细记录(更新中) - 文章图片](/upload/getfiles/0001/2021/5/4/20210504042526015.jpg)
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 using namespace std; 5 typedef long long ll; 6 //吐槽:WA一次。原因是不会输出 Loowater is doomed。由于原代码没有判断骑士是否已经杀了一个头。鉴于题目里提到n>=1.所以一旦有骑士杀了龙,那么就让骑士 b[i]=-1,这样他就相当于被标记过了。本来还想开个bool vis数组记录一下。 7 bool dragon(int x,int y) 8 { 9 return x>y; 10 } 11 bool ability(int x,int y) 12 { 13 return x<y; 14 } 15 16 int main() 17 { 18 int n,m,a[20000+5],b[20000+5],cnt; ll x; 19 while(scanf("%d%d",&n,&m)==2) 20 { 21 if(m==n&&n==0) 22 break; 23 x=cnt=0; 24 bool flag=false; 25 for(int i=0;i<n;++i) 26 scanf("%d",&a[i]); 27 for(int i=0;i<m;++i) 28 scanf("%d",&b[i]); 29 sort(a,a+n,dragon); 30 sort(b,b+m,ability); 31 for(int i=0;i<n;++i)//head 32 { 33 int t=cnt; 34 for(int j=0;j<m;j++)//person 35 { 36 if(a[i]<=b[j]) 37 { 38 cnt++; 39 x+=b[j]; 40 b[j]=-1; 41 break; 42 } 43 44 } 45 if(cnt!=t+1) 46 {flag=true;break;} 47 } 48 if(flag||cnt!=n) 49 printf("Loowater is doomed!\n"); 50 else{ 51 printf("%lld\n",x); 52 } 53 } 54 }UVA11292:The Dreagon of Loowater
![算法竞赛入门经典训练指南-做题详细记录(更新中) - 文章图片](/upload/getfiles/0001/2021/5/4/20210504042525909.jpg)
![算法竞赛入门经典训练指南-做题详细记录(更新中) - 文章图片](/upload/getfiles/0001/2021/5/4/20210504042526015.jpg)
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 using namespace std; 5 typedef long long ll; 6 7 struct per{ 8 int b; 9 int j; 10 bool operator < (const per& x) const{return j>x.j;}//第一次尝试不用cmp函数 11 }p[1000+7]; 12 // 13 //bool cmp(per x,per y) 14 //{ 15 // return x.j>y.j; 16 //} 17 int main() 18 { 19 int n,cas=0,s,ans; 20 while(scanf("%d",&n)==1&&n) 21 { 22 ans=s=0; 23 cas++; 24 for(int i=0;i<n;++i) 25 scanf("%d%d",&p[i].b,&p[i].j); 26 sort(p,p+n); // sort(p,p+n,cmp); 27 for(int i=0;i<n;++i){ 28 s+=p[i].b; 29 ans=max(ans,s+p[i].j); 30 } 31 printf("Case %d: %d\n",cas,ans); 32 } 33 return 0; 34 }UVA11729:Commando War
。
内容总结
以上是互联网集市为您收集整理的算法竞赛入门经典训练指南-做题详细记录(更新中)全部内容,希望文章能够帮你解决算法竞赛入门经典训练指南-做题详细记录(更新中)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。