Codeforces Round #308 (Div. 2) A B C D E
来源:互联网 发布:java string搜索 编辑:程序博客网 时间:2024/05/16 04:38
A Vanya and Table
水。
#include <bits/stdc++.h>using namespace std;int mp[110][110];int main(){int n;while(cin>>n){int ans=0;while(n--){int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;ans+=(x2-x1+1)*(y2-y1+1);}cout<<ans<<endl;}return 0;}
B Vanya and Books
统计1~n的所有数中,共有多少数字。随便统计一下就好了。
#include <bits/stdc++.h>using namespace std;#define ll long longint main(){ll n;cin>>n;ll ans=0;if(n-1e9>=0){ans+=(n-1e9+1);}if(n-1e8>=0){ans+=(n-1e8+1);}if(n-1e7>=0){ans+=(n-1e7+1);}if(n-1e6>=0){ans+=(n-1e6+1);}if(n-1e5>=0){ans+=(n-1e5+1);}if(n-1e4>=0){ans+=(n-1e4+1);}if(n-1e3>=0){ans+=(n-1e3+1);}if(n-1e2>=0){ans+=(n-1e2+1);}if(n-1e1>=0){ans+=(n-1e1+1);}if(n-1>=0){ans+=(n-1e0+1);}cout<<ans<<endl;return 0;}
C Vanya and Scales
给w和m两个数,你有一个天平,砝码质量为w^0,w^1,w^2...w^100。问能否称出m。
贪心,先用大砝码,后用小的,每次使需要称的重量变小就可以了,看看能不能得到0。
#include <bits/stdc++.h>using namespace std;#define ll long longint main(){ll w,m;cin>>w>>m;ll tmp=w;while(tmp<m)tmp*=w;bool ok=0;while(1){if(tmp>m){if(tmp-m<m){m=tmp-m;}}else{m-=tmp;}if(m==0){ok=1;break;}tmp/=w;if(tmp==0)break;}if(ok){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}return 0;}
D Vanya and Triangles
计算一个点集能构成多少三角形,其实就是问有多少组三点共线,竟然可以暴力过。
#include <bits/stdc++.h>using namespace std;#define ll long longint x[2010];int y[2010];int main(){int n;cin>>n;for(int i=1;i<=n;i++){scanf("%d%d",&x[i],&y[i]);}ll ans=0;for(int k=1;k<=n;k++){for(int i=k+1;i<=n;i++){x[i]-=x[k];y[i]-=y[k];}for(int i=k+1;i<=n;i++){for(int j=i+1;j<=n;j++){if(x[i]*y[j]!=x[j]*y[i]){ans++;}}}} cout<<ans<<endl;return 0;}
E Vanya and Brackets
一个只含'+'和'*'的表达式,添加一个括号,使得结果尽可能大。
稍微分析一下就可以知道,最优解的括号两边,要么是乘号,要么是开头末尾。。枚举所有添加括号方法用栈处理下表达式就可以了。
#include <bits/stdc++.h>using namespace std;string str;string str2;#define ll long longstack<ll> num;stack<char> op;ll calc(){for(int i=0;i<str.size();i++){if(str[i]=='+'){op.push(str[i]);}else if(str[i]=='*'){op.push(str[i]);}else if(str[i]=='('){op.push(str[i]);}else if(str[i]==')'){while(op.top()!='('){char o=op.top();op.pop();ll a=num.top();num.pop();ll b=num.top();num.pop();if(o=='+'){num.push(a+b);}else{num.push(a*b);}}op.pop();if(op.size()&&op.top()=='*'){op.pop();ll a=num.top();num.pop();ll b=num.top();num.pop();num.push(a*b);}}else{num.push(str[i]-'0');if(op.size()&&op.top()=='*'){op.pop();ll a=num.top();num.pop();ll b=num.top();num.pop();num.push(a*b);}}}while(op.size()){char o=op.top();op.pop();ll a=num.top();num.pop();ll b=num.top();num.pop();if(o=='+'){num.push(a+b);}else{num.push(a*b);}}ll re=num.top();num.pop();return re;}int pos[5010];int main(){cin>>str;str2=str;int len=str.size();ll ans=calc();int cnt=0;for(int i=0;i<len;i++){if(str[i]=='*'){pos[++cnt]=i;}}for(int i=1;i<=cnt;i++){str=str2;str.insert(0,1,'(');str.insert(pos[i]+1,1,')');ans=max(ans,calc());}for(int i=1;i<=cnt;i++){str=str2;str.insert(pos[i]+1,1,'(');str.insert(len+1,1,')');ans=max(ans,calc());}for(int i=1;i<cnt;i++){for(int j=i+1;j<=cnt;j++){str=str2;str.insert(pos[i]+1,1,'(');str.insert(pos[j]+1,1,')');ans=max(ans,calc());}}cout<<ans<<endl;return 0;}
0 0
- Codeforces Round #308 (Div. 2) A B C D E
- Codeforces Round #186 (Div. 2)A、B、C、D、E
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #263 (Div. 2) A,B,C,D,E
- Codeforces Round #264 (Div. 2) A,B,C,D,E
- Codeforces Round #277 (Div. 2) A,B,C,D,E
- Codeforces Round #280 (Div. 2 A,B,C,D,E)
- Codeforces Round #287 (Div. 2) A、B、C、D、E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #288 (Div. 2) A,B,C,D,E
- Codeforces Round #293 (Div. 2) (A B C D E)
- Codeforces Round #312 (Div. 2) A B C D E
- Codeforces Round #311 (Div. 2) A,B,C,D,E
- Codeforces Round #320 (Div. 2) A B C D E
- Codeforces Round #330 (Div. 2)(A,B,C,D,E)
- Codeforces Round #346 (Div. 2) A B C D E
- Codeforces Round #346 (Div. 2) A.B.C.D.E
- 联诚发(LCF)派礼物,平平安安过端午
- 变量名和地址之间的关系
- Eclipse各种抓狂问题集锦(一)
- JAVA判断文件编码类型
- [android](仿联系人)带分类、分类顶部保留替换ListView——StickyList
- Codeforces Round #308 (Div. 2) A B C D E
- 数据库的知识点总结
- Tasks and Back Stack
- OC学习--选择器(Selector)
- 关于乐观锁和悲观锁的介绍
- 算法——因子和阶乘
- Linux下的多线程机制--生产者和消费者实例
- 练习代码(一)初始化与清理
- github 上传项目 过滤到cocoapods无用文件