Codeforces Beta Round #4 (Div. 2 Only)
Codeforces Beta Round #4 (Div. 2 Only)
A
水题
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 struct sair{ 11 ll a,b; 12 int pos; 13 bool operator<(const sair&bb)const{ 14 return (b-a)<(bb.b-bb.a); 15 } 16 }; 17 18 int main(){ 19 #ifndef ONLINE_JUDGE 20 freopen("1.txt","r",stdin); 21 #endif 22 int n; 23 cin>>n; 24 if(n%2==0&&n!=2&&n!=0) cout<<"YES"<<endl; 25 else cout<<"NO"<<endl; 26 }
View Code
B
判断给定时间在不在最大值之和和最小值之和之间即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 struct sair{ 11 ll a,b; 12 int pos; 13 bool operator<(const sair&bb)const{ 14 return (b-a)<(bb.b-bb.a); 15 } 16 }; 17 18 int a[1005],b[1005]; 19 20 int main(){ 21 #ifndef ONLINE_JUDGE 22 // freopen("1.txt","r",stdin); 23 #endif 24 int n,m; 25 cin>>n>>m; 26 int Min=0,Max=0; 27 for(int i=0;i<n;i++){ 28 cin>>a[i]>>b[i]; 29 Min+=a[i]; 30 Max+=b[i]; 31 } 32 if(Min<=m&&m<=Max){ 33 cout<<"YES"<<endl; 34 vector<int>ans; 35 for(int i=0;i<n;i++){ 36 ans.push_back(a[i]); 37 m-=a[i]; 38 } 39 for(int i=0;i<ans.size();i++){ 40 if(m==0) break; 41 int tmp=b[i]-a[i]; 42 if(m>tmp) m-=tmp; 43 else {tmp=m,m=0;} 44 ans[i]+=tmp; 45 } 46 for(int i=0;i<ans.size();i++){ 47 cout<<ans[i]<<" "; 48 } 49 cout<<endl; 50 } 51 else{ 52 cout<<"NO"<<endl; 53 } 54 55 }
View Code
C
直接上map即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 struct sair{ 11 ll a,b; 12 int pos; 13 bool operator<(const sair&bb)const{ 14 return (b-a)<(bb.b-bb.a); 15 } 16 }; 17 18 int a[1005],b[1005]; 19 20 string Change(int x){ 21 string str=""; 22 while(x){ 23 str+=char(x%10+'0'); 24 x/=10; 25 } 26 for(int i=0;i<str.length()/2;i++){ 27 char tmp=str[i]; 28 str[i]=str[str.length()-1-i]; 29 str[str.length()-1-i]=tmp; 30 } 31 return str; 32 } 33 34 int main(){ 35 #ifndef ONLINE_JUDGE 36 freopen("1.txt","r",stdin); 37 #endif 38 int n; 39 map<string,int>mp; 40 cin>>n; 41 string str; 42 for(int i=1;i<=n;i++){ 43 cin>>str; 44 if(mp[str]==0){ 45 cout<<"OK"<<endl; 46 mp[str]=1; 47 } 48 else{ 49 string tmp=Change(mp[str]); 50 mp[str]++; 51 str+=tmp; 52 mp[str]=1; 53 cout<<str<<endl; 54 } 55 } 56 57 }
View Code
D
找最长上升子序列,DP水题
因为是二维排序的关系,所以最后一个位置的值不一定是最大的,所以要遍历一遍数组找最大值
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 11 int n,w,h; 12 struct sair{ 13 int w,h,pos; 14 }a[5005]; 15 16 bool cmp(sair aa,sair bb){ 17 if(aa.h==bb.h) return aa.w<bb.w; 18 return aa.h<bb.h; 19 } 20 21 int dp[5005],Index[5005]; 22 23 void dfs(int pos){ 24 if(!a[pos].pos) return; 25 dfs(Index[pos]); 26 cout<<a[pos].pos<<" "; 27 } 28 29 int main(){ 30 #ifndef ONLINE_JUDGE 31 // freopen("1.txt","r",stdin); 32 #endif 33 int tot; 34 cin>>tot>>a[1].w>>a[1].h; 35 int i; 36 n=1; 37 for(i=1;i<=tot;i++){ 38 cin>>w>>h; 39 if(w>a[1].w&&h>a[1].h){ 40 a[++n].w=w; 41 a[n].h=h; 42 a[n].pos=i; 43 } 44 } 45 sort(a+1,a+n+1,cmp); 46 47 for(int i=2;i<=n;i++){ 48 for(int j=1;j<=i;j++){ 49 if(a[i].w>a[j].w&&a[i].h>a[j].h&&dp[i]<=dp[j]){ 50 dp[i]=dp[j]+1; 51 Index[i]=j; 52 } 53 } 54 } 55 int Max=0; 56 int pos=0; 57 for(int i=1;i<=n;i++){ 58 if(Max<dp[i]){ 59 Max=dp[i]; 60 pos=i; 61 } 62 } 63 cout<<dp[pos]<<endl; 64 dfs(pos); 65 }
View Code
当然,因为第一个比所有的都小,所以也可以从后往前DP,相当于DP最长下降子序列,这样下标为1的位置的值是最大的
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 11 int n,w,h; 12 struct sair{ 13 int w,h,pos; 14 }a[5005]; 15 16 bool cmp(sair aa,sair bb){ 17 if(aa.h==bb.h) return aa.w<bb.w; 18 return aa.h<bb.h; 19 } 20 21 int dp[5005],Index[5005]; 22 23 void dfs(int pos){ 24 if(!a[pos].pos) return; 25 dfs(Index[pos]); 26 cout<<a[pos].pos<<" "; 27 } 28 29 int main(){ 30 #ifndef ONLINE_JUDGE 31 freopen("1.txt","r",stdin); 32 #endif 33 int tot; 34 cin>>tot>>a[1].w>>a[1].h; 35 int i; 36 n=1; 37 for(i=1;i<=tot;i++){ 38 cin>>w>>h; 39 if(w>a[1].w&&h>a[1].h){ 40 a[++n].w=w; 41 a[n].h=h; 42 a[n].pos=i; 43 } 44 } 45 sort(a+1,a+n+1,cmp); 46 for(int i=n-1;i>=1;i--){ 47 for(int j=i+1;j<=n;j++){ 48 if(a[i].w<a[j].w&&a[i].h<a[j].h&&dp[i]<=dp[j]){ 49 dp[i]=dp[j]+1; 50 Index[i]=j; 51 } 52 } 53 } 54 cout<<dp[1]<<endl; 55 int pos=Index[1]; 56 while(pos){ 57 cout<<a[pos].pos<<" "; 58 pos=Index[pos]; 59 } 60 }
View Code
转载于:https://www.cnblogs.com/Fighting-sh/p/10341026.html
Codeforces Beta Round #4 (Div. 2 Only)相关推荐
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)
题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...
- Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力
A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...
- Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp
D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old t ...
- Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题
B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...
- Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心
D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...
- Codeforces Beta Round #9 (Div. 2 Only) C. Hexadecimal's Numbers dfs
C. Hexadecimal's Numbers 题目连接: http://www.codeforces.com/contest/9/problem/C Description One beautif ...
- Codeforces Beta Round #16 (Div. 2 Only)【未完结】
2022.3.9 题目地址:https://codeforces.com/contest/16 目录 A. Flag[模拟] B. Burglar and Matches[贪心] C. Monitor ...
- Codeforces Beta Round #14 (Div. 2)【未完结】
2022.3.8 题单地址:https://codeforces.com/contest/14 目录 A. Letter B. Young Photographer[差分] C. Four Segme ...
最新文章
- vue 富文本存储_Vue富文本编辑器
- exfat 分配单元大小_知到金融理论与实务第一单元章节测试答案
- OpenCV角点检测之Harris角点检测
- boost::geometry::index::detail::segment_intersection用法的测试程序
- Unity整合TortoiseSVN
- Apache Server和JMeter调试
- 戴森发布限量版V11 Complete智能无绳吸尘器
- (最短路径算法整理)dijkstra、floyd、bellman-ford、spfa算法模板的整理与介绍
- 结构化元素、网页结构和iframe内联框架
- easyUI中datagrid中getSelected和getSelections的用法
- 博文视点学院直播:如何用产品思维解决生活中的迷茫
- VC++监听数据分析出明文账号密码
- 关于extern的使用
- 自然语言表示简史(BERT/ELMO/Word2vec/LDA/Bow/Ohehot,词向量、句向量、优缺点、应用与解决的问题)
- 都2022年了,PPT这些酷炫操作我不允许你不知道
- Matlab常用函数集锦
- C 合成的图片文件的小练习
- Sobel和Roberts算子的推导过程
- iOS精品资源汇总(持续更新)
- 计算网络节点的平均度