Educational Codeforces Round 21 C. Tea Party
来源:互联网 发布:ubuntu root默认密码 编辑:程序博客网 时间:2024/05/29 07:17
觉得这题挺有趣的.. 不过直接暴力过了 不知道还有没有什么更好地方法
见注释
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<string>#include<stack>#include<queue>#include<cmath>#include<stack>#include<list>#include<map>using namespace std;typedef long long ll;int a[105];int b[105];int main(){ int n,w,i,j,k; while(scanf("%d%d",&n,&w)==2) { int sum2=0; int w1=w; for(i=1;i<=n;i++) { scanf("%d",&a[i]); b[i]=a[i]; if(a[i]%2==0) { sum2+=a[i]/2; b[i]-=a[i]/2; //相当于已经在a[i]中倒了一半的水 b[i]为剩下的容量 w1-=a[i]/2; //壶里还剩下多少茶 } else { sum2+=a[i]/2+1; //与if语句同理 b[i]-=a[i]/2+1; w1-=a[i]/2+1; } } if(w1<0) //茶不够 { printf("-1\n"); continue; } while(w1!=0) //这题n比较小 w的最大值也很小 直接暴力过了..没想到这么水.. { int t=0; int maxn=-1; for(i=1;i<=n;i++) { if(b[i]>maxn) //求出剩余容量最大的那个 容器的容量大的比容量小的 装满一半后 未装一半的容量肯定还大 else if中有个特例 { maxn=b[i]; t=i; } else if(b[i]==maxn) { if(a[i]%2==1) // 若a[i]==9 则剩下4 若a[i]==8 也剩下4 根据题意我们要优先装容量大的 所以要记录a[i]为奇数的下标 { t=i; } } } if(w1-b[t]>=0) //if else 里语句很好理解吧.. { w1-=b[t]; b[t]=0; } else { b[t]-=w1; w1=0; } } for(i=1;i<=n;i++) { printf("%d%c",a[i]-b[i],i==n?'\n':' '); //输出a[i]-b[i],就是最终结果了 } } return 0;}
阅读全文
1 0
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21-----C. Tea Party
- Educational Codeforces Round 21 C Tea Party
- codeforces Educational Codeforces Round 21 C. Tea Party
- Educational Codeforces Round 21 808C Tea Party 【贪心算法】
- Educational Codeforces Round 21 C. Tea Party 贪心
- Codeforces Educational Codeforces Round 21 [5.30] Tea Party&Array Division&Average Sleep Time&Lucky
- Codeforces 808C Tea Party
- Codeforces 808C Tea Party
- Educational Codeforces Round 21 C
- 【codeforces 808】C.Tea Party(贪心)
- Codeforces 808C Tea Party 题解
- 【Codeforces 808 C. Tea Party】+ sort
- Codeforces 808C Tea Party【贪心】
- 【Codeforces 808C】【贪心】Tea Party题解
- Educational Codeforces Round 21
- php基础--Hello,World!
- AVL树删除
- 运算符重载学习笔记
- JDBC总结
- Linux——Vim命令集
- Educational Codeforces Round 21 C. Tea Party
- sql语句中使用的小问题
- Android 更新UI的两种方法——handler和runOnUiThread()
- Cmd Markdown 简明语法手册
- 计算机网络——物理层和数据链路层
- JMeter 集合点设置之Synchronizing Timer的使用
- hdu 2037 今年暑假不AC
- OpenCV——WIN10+VS2015配置
- TCP的主要特性