微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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",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,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",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水题

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。