Codeforces Round #322 (Div. 2)
2016-07-25 15:13
330 查看
传送门:A. Vasya the Hipster (极水题)
传送门:B. Luxurious Houses (水题)
题意:~
思路:也是水题一枚,从后往前扫一遍就不会TLE了
传送门:C. Developing Skills (贪心)
思路:这是一道简单的贪心,我们将每一个数字按照最后一位的大小排一个序,然后优先加给最后一位大的,如果有多的那么就分给每一个,然是不能超过100(刚开始没注意这个WA在test5了)
题意:
给你三个矩形,问你是否能拼成一个正方形
思路:这题数据小,无脑暴力也行,但是CF的题经常是可以通过多思考来优化的
这个题首先明确能构成正方形的充要条件就是:最长边^2=三个矩形的面积和,同时这个最长边即作为正方形的边长len。具体地,首先得到三个矩形的长宽,先旋转为卧倒的矩形(上下边>=左右腰)。之后找到最长边,判断能否构成正方形。如果能,那么这个最长边的矩形一定可以卧放在正方形的顶部(也可以放在其他地方,但一定可以旋转到顶部)。
然后剩下下面的部分,这个地方有一些陷阱,最简单规避陷阱的方法就是分情况讨论,要不然就是三个矩形都依次卧放;要不就是两个矩形都竖着放。那么就试着枚举一下,随便选一个剩下的矩形(这里称之为X),如果X的较长边==len或者X的较短边刚好加上顶上矩形的腰长==len,那么就不用旋转;否则就旋转。最后的一个矩形把剩下的地方补齐即可。
#include <bits/stdc++.h> #define pr(x) cout << #x << "= " << x << " " #define pl(x) cout << #x << "= " << x << endl; #define Memset(x, a) memset(x, a, sizeof(x)) #define ll __int64 using namespace std; const int inf=0x3f3f3f3f; int a,b; int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin>>a>>b; if(a>b)swap(a,b); cout<<a<<" "<<(b-a)/2<<endl; return 0; }
传送门:B. Luxurious Houses (水题)
题意:~
思路:也是水题一枚,从后往前扫一遍就不会TLE了
#include <bits/stdc++.h> #define pr(x) cout << #x << "= " << x << " " #define pl(x) cout << #x << "= " << x << endl; #define Memset(x, a) memset(x, a, sizeof(x)) #define ll __int64 using namespace std; const int inf=0x3f3f3f3f; int n,a[100005],ans[100005]; int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); std::ios::sync_with_stdio(false); std::cin.tie(0); cin>>n; for(int i=0; i<n; i++){ cin>>a[i]; } int b=0; ans[n-1]=0; for(int i=n-1; i>=1; i--){ b=max(b,a[i]); if(b<a[i-1])ans[i-1]=0; else ans[i-1]=b-a[i-1]+1; } for(int i=0; i<n; i++){ cout<<ans[i]<<" "; } cout<<endl; return 0; }
传送门:C. Developing Skills (贪心)
思路:这是一道简单的贪心,我们将每一个数字按照最后一位的大小排一个序,然后优先加给最后一位大的,如果有多的那么就分给每一个,然是不能超过100(刚开始没注意这个WA在test5了)
#include <bits/stdc++.h> #define pr(x) cout << #x << "= " << x << " " #define pl(x) cout << #x << "= " << x << endl; #define Memset(x, a) memset(x, a, sizeof(x)) #define ll __int64 using namespace std; const int inf=0x3f3f3f3f; int n,k,a[100005],b[100005]; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f; } int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); std::ios::sync_with_stdio(false); std::cin.tie(0); n=read();k=read(); int ans=0,cnt=0; for(int i=1; i<=n; i++){ a[i]=read(); ans+=a[i]/10; if(a[i]==100)continue;//先把等于100情况除去 b[++cnt]=10-a[i]%10; a[i]+=b[cnt]; } sort(b+1,b+cnt+1); bool flag=true; for(int i=1; i<=cnt; i++){ if(k>=b[i]){ ans++; k-=b[i];} else{ flag=false; break; } } if(flag){ //如果k有的多 int sum=0; for(int i=1; i<=n; i++){ sum+=(100-a[i])/10; } ans+=min(sum,k/10); //再多也不能超100 } cout<<ans<<endl; return 0; }传送门:D. Three Logos (暴力)
题意:
给你三个矩形,问你是否能拼成一个正方形
思路:这题数据小,无脑暴力也行,但是CF的题经常是可以通过多思考来优化的
这个题首先明确能构成正方形的充要条件就是:最长边^2=三个矩形的面积和,同时这个最长边即作为正方形的边长len。具体地,首先得到三个矩形的长宽,先旋转为卧倒的矩形(上下边>=左右腰)。之后找到最长边,判断能否构成正方形。如果能,那么这个最长边的矩形一定可以卧放在正方形的顶部(也可以放在其他地方,但一定可以旋转到顶部)。
然后剩下下面的部分,这个地方有一些陷阱,最简单规避陷阱的方法就是分情况讨论,要不然就是三个矩形都依次卧放;要不就是两个矩形都竖着放。那么就试着枚举一下,随便选一个剩下的矩形(这里称之为X),如果X的较长边==len或者X的较短边刚好加上顶上矩形的腰长==len,那么就不用旋转;否则就旋转。最后的一个矩形把剩下的地方补齐即可。
#include <bits/stdc++.h> #define pr(x) cout << #x << "= " << x << " " #define pl(x) cout << #x << "= " << x << endl; #define Memset(x, a) memset(x, a, sizeof(x)) #define ll __int64 using namespace std; const int inf=0x3f3f3f3f; struct Rec { int l, w; char ch; bool operator <( const Rec& rhs )const{ return l < rhs.l; } int sq(){ return l*w; } }rec[4]; int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(scanf( "%d%d%d%d%d%d", &rec[1].l, &rec[1].w, &rec[2].l, &rec[2].w, &rec[3].l, &rec[3].w ) == 6) { for(int i = 1; i <= 3; i++){ if(rec[i].l < rec[i].w)swap( rec[i].l, rec[i].w ); rec[i].ch = 'A' - 1 + i; } sort( rec + 1, rec + 4 ); int len = rec[3].l; if((rec[3].l*rec[3].l) != (rec[1].sq() + rec[2].sq() + rec[3].sq())) { printf( "-1\n" ); continue; } printf( "%d\n", len ); for(int i = 1; i <= rec[3].w; i++){ for(int j = 1; j <= rec[3].l; j++){ printf( "%c", rec[3].ch ); } printf( "\n" ); } if(rec[2].l!=len&&rec[3].w + rec[2].w != len) swap( rec[2].l, rec[2].w ); for(int i = 1; i <= rec[2].w; i++){ for(int j = 1; j <= rec[2].l; j++){ printf( "%c", rec[2].ch ); }for(int j = 1; j <= len - rec[2].l; j++){ printf( "%c", rec[1].ch ); } printf( "\n" ); } for(int i = 1; i <=len-rec[3].w- rec[2].w; i++){ for(int j = 1; j <= len; j++){ printf( "%c", rec[1].ch ); } printf( "\n" ); } } return 0; }
相关文章推荐
- LVM逻辑卷管理
- onload事件--addLoadEvent函数--我的改进
- 给电脑端网页添加手机适配
- android SQLite疑点分析
- 2016003 VS2008MFC扩展动态库与调用示例
- 8086汇编语言自学经验分享 使用offset命令获取标号的IP地址
- HTML5本地存储之Database Storage篇
- Git 版本回退与前进(03)
- vagrant入门教程--初始化虚拟机(5)
- MLAPP学习笔记-KNN与K-means引发的思考
- Android OkHttp
- Google IAB Serivce 集成大坑 (InAppBilling)
- Ubuntu下Apache配置与详解【原创】
- 度量学习(Distance Metric Learning)介绍
- Json转Map
- JavaScript 上传文件
- 解决checkbox的attr(checked)一直为undefined问题
- java基础四 [构造器和垃圾回收](阅读Head First Java记录)
- 349. Intersection of Two Arrays
- 部分安卓机型 页面无法跳转