Codeforces Round #381 (Div. 2) #V
来源:互联网 发布:手机淘宝 卖家中心 编辑:程序博客网 时间:2024/06/06 01:29
A.
题意:给出n,a,b,c 只有一种书,书有无穷本,同一个套餐可以买多次,购买书有三种套餐: a套餐代表一次性买1本书的价格,b代表买2本书的价格,c代表买3本书的价格,
要求(n+k)%4==0,问买k本书花费的最小金钱
思路:水题,
if n已经是4的倍数就不用买了,
else if 还差2本:购买方式可以是:2次a或者1次b或者2次c,哪种方法便宜就用哪种
else if 还差1本:购买方式可以是 :1次a 或者 1次b+1次c 或者 3次c;
else if 还差3本 同理:ans=min1(3*a,a+b,c);
哈哈,轻松A一题0.0
B.
题意:给出一个大小为N的数组,再给出M个区间,选取若干区间,使得happy值最大,happy值定义:区间的元素和(N,M<=100)
思路:NM很小,暴力各区间元素和sum,sum>=0说明对ans有贡献。
哈哈,又A一题,知道题意就秒解了。
C.
题意:定义mex(l,r):返回不等于 数组A在区间【l,r】的所有元素的第一个非0的数,比如A{0,0,1,3} mex(1,3)=2;
现在给出数组A的大小N,和M个区间,要求每个区间的mex尽量大,输出所有区间的最小mex,并构造符合的数组A,输出之
思路:要求每个区间mex尽量大,那么只能从0开始0123...这样,显然最小mex就是区间大小,
怎么构造?比如mex=4构造数组0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3...肯定能满足要求
目标是每次都3题
第一篇博客,有点小激动0.0
A题代码:
ll min1(ll a,ll b,ll c){ll ans=0;ans=min(a,b);ans=min(ans,c);return ans;}int main(){ll n,a,b,c; cin>>n>>a>>b>>c; if(n%4==0) { printf("0\n"); } else if(n%4==1) { printf("%I64d",min1(3*a,a+b,c)); } else if(n%4==2) { printf("%I64d",min1(2*a,b,2*c)); } else if(n%4==3) { printf("%I64d",min1(a,b+c,3*c)); }return 0;}
B题代码:
int a1[105];ll count(int a,int b){ll t=0;for(int i=a;i<=b;i++){t+=a1[i];}return t;}int main(){ll n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a1[i];}ll ans=0;for(int i=0;i<m;i++){int a,b;cin>>a>>b;if(count(a,b)>0){ans+=count(a,b);}}cout<<ans<<endl;return 0;}
int a1[100005];int main(){int n,m;cin>>n>>m;int mex=1000000;for(int i=0;i<m;i++){int a,b;cin>>a>>b;mex=min(b-a+1,mex);}int t=0;for(int i=1;i<=n;i++){a1[i]=t;t++;if(t==mex)t=0;}cout<<mex<<endl;for(int i=1;i<=n;i++){cout<<a1[i]<<" ";}cout<<endl;return 0;}
阅读全文
1 0
- Codeforces Round #381 (Div. 2) #V
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2)
- Codeforces Round #381 (Div. 2) &&Codeforce_740
- Codeforces Round #381 (Div. 1)
- Codeforces Round #381 (Div. 1)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- xss挑战赛-wp
- mysql性能优化之profiling
- 2018网易校招笔试题之疯狂队列
- Python随机选择
- win10+go+beego搭建用户管理系统
- Codeforces Round #381 (Div. 2) #V
- 用css做的风琴相册
- Visual Studio如何设置背景
- python 的xml解析
- php、nginx 两个分开的容器相连连不上的问题总结
- FreeRTOS在STM32F4上移植
- js之二级伸缩栏目+多选框+开关门
- 竖式问题
- RILD