Codeforces Beta Round #40 (Div. 2)

Codeforces Beta Round #40 (Div. 2)

http://codeforces.com/contest/41

A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define maxn 1000006
 5 
 6 
 7 int main(){
 8     #ifndef ONLINE_JUDGE
 9      //   freopen("input.txt","r",stdin);
10     #endif
11     std::ios::sync_with_stdio(false);
12     string s1,s2;
13     cin>>s1>>s2;
14     if(s1.length()==s2.length()){
15         for(int i=0;i<s1.length();i++){
16             if(s1[i]!=s2[s1.length()-i-1]){
17                 cout<<"NO"<<endl;
18                 return 0;
19             }
20         }
21         cout<<"YES"<<endl;
22         return 0;
23     }
24     cout<<"NO"<<endl;
25 }
View Code

 

B

贪心,每种情况枚举过去,买的话建一个优先队列存最小值

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define maxn 1000006
 5 
 6 int a[2005];
 7 int c[2005][2005];
 8 int n,b;
 9 
10 int main(){
11     #ifndef ONLINE_JUDGE
12         freopen("input.txt","r",stdin);
13     #endif
14     std::ios::sync_with_stdio(false);
15     cin>>n>>b;
16     for(int i=1;i<=n;i++) cin>>a[i];
17     int ans=b;
18     priority_queue<int,vector<int>, greater<int> >Q;
19     Q.push(a[1]);
20     for(int i=2;i<=n;i++){
21         int tmp=b;
22         vector<int>ve;
23         ve.clear();
24         for(int j=1;j<i;j++){
25             if(!Q.empty()&&tmp>Q.top()){
26                 ve.push_back(Q.top());
27                 ans=max(ans,tmp/Q.top()*a[i]+tmp%Q.top());
28                 tmp%=Q.top();
29             }
30         }
31         Q.push(a[i]);
32         for(int j=0;j<ve.size();j++){
33             Q.push(ve[j]);
34         }
35     }
36     cout<<ans<<endl;
37 }
View Code

 

C

模拟

 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 #define pb push_back
 7 #define eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16 
17 
18 int main(){
19     #ifndef ONLINE_JUDGE
20         freopen("input.txt","r",stdin);
21     #endif
22     std::ios::sync_with_stdio(false);
23     string str;
24     cin>>str;
25     cout<<str[0];
26     int flag=0;
27     for(int i=1;i<str.length();i++){
28         if(str[i]=='d'&&i<str.length()-3){
29             if(str[i+1]=='o'&&str[i+2]=='t'){
30                 cout<<'.';
31                 i+=2;
32             }
33             else{
34                 cout<<str[i];
35             }
36         }
37         else if(str[i]=='a'){
38             if(str[i+1]=='t'&&!flag){
39                 cout<<'@';
40                 flag=1;
41                 i++;
42             }
43             else{
44                 cout<<str[i];
45             }
46         }
47         else{
48             cout<<str[i];
49         }
50     }
51 }
View Code

 

D

DP

有句话说的好,DP不行,再加一维。。。

加上的那一维为到该点的值

复杂度为O(n*m*9*n)

注意,0也算是k+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 #define pb push_back
 7 #define eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16 int n,m,kk;
17 string str[105];
18 bool dp[105][105][905];
19 short pre[105][105][905];
20 
21 void dfs(int floor,int pos,int v){
22     if(floor==n-1){
23         cout<<pos+1<<endl;
24         return;
25     }
26     dfs(floor+1,pre[floor][pos][v],v-(str[floor][pos]-'0'));
27     if(pre[floor][pos][v]<pos){
28         cout<<'R';
29     }
30     else{
31         cout<<'L';
32     }
33 }
34 
35 int main(){
36     #ifndef ONLINE_JUDGE
37         freopen("input.txt","r",stdin);
38     #endif
39     std::ios::sync_with_stdio(false);
40     cin>>n>>m>>kk;
41     for(int i=0;i<n;i++) cin>>str[i];
42     for(int i=0;i<m;i++){
43         dp[n-1][i][str[n-1][i]-'0']=1;
44     }
45     for(int i=n-2;i>=0;i--){
46         for(int j=0;j<m;j++){
47             for(int k=0;k<=900;k++){
48                 if(dp[i+1][j][k]){
49                     if(j-1>=0){
50                         dp[i][j-1][k+str[i][j-1]-'0']=1;
51                         pre[i][j-1][k+str[i][j-1]-'0']=j;
52                     }
53                     if(j+1<m){
54                         dp[i][j+1][k+str[i][j+1]-'0']=1;
55                         pre[i][j+1][k+str[i][j+1]-'0']=j;
56                     }
57                 }
58             }
59         }
60     }
61     int Max=-1;
62     int pos=0;
63     for(int i=0;i<m;i++){
64         for(int j=900;j>=0;j--){
65             if((dp[0][i][j]==1)&&(j%(kk+1)==0)){
66                 if(Max<j){
67                     Max=j;
68                     pos=i;
69                 }
70             }
71         }
72     }
73     if(Max==-1){
74         cout<<-1<<endl;
75         return 0;
76     }
77     cout<<Max<<endl;
78     dfs(0,pos,Max);
79 }
View Code

 

E

找规律,题意说不存在3的循环,所以可以把图看成二分图

边的总数为:(n/2)*(n/2+n%2)

 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 #define pb push_back
 7 #define eps 1e-8
 8 #define PI acos(-1.0)
 9 #define maxn 1000005
10 typedef long long ll;
11 typedef unsigned long long ull;
12 
13 /*#ifndef ONLINE_JUDGE
14         freopen("1.txt","r",stdin);
15 #endif */
16 
17 int main(){
18     #ifndef ONLINE_JUDGE
19       //  freopen("input.txt","r",stdin);
20     #endif
21     std::ios::sync_with_stdio(false);
22     int n;
23     cin>>n;
24     if(n==1){
25         cout<<0<<endl;
26     }
27     else if(n==2){
28         cout<<1<<endl;
29         cout<<"1 2"<<endl;
30     }
31     else{
32         cout<<(n/2)*(n/2+n%2)<<endl;
33         for(int i=1;i<=n/2;i++){
34             for(int j=n/2+1;j<=n;j++){
35                 cout<<i<<" "<<j<<endl;
36             }
37         }
38     }
39 }
View Code

 

posted on 2019-02-18 13:06  Fighting_sh  阅读(211)  评论(0编辑  收藏  举报

导航