Codeforces Beta Round #6 (Div. 2 Only)

Codeforces Beta Round #6 (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 #define maxn 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int Check(int a,int b,int c){
13     if(a+b>c&&a+c>b&&b+c>a) return 1;
14     if(a+b==c||a+c==b||b+c==a) return 0;
15     return -1;
16 }
17 
18 int main(){
19     #ifndef ONLINE_JUDGE
20       //  freopen("1.txt","r",stdin);
21     #endif
22     int a,b,c,d;
23     cin>>a>>b>>c>>d;
24     int flag=-1;
25     flag=max(flag,Check(a,b,c));
26     flag=max(flag,Check(a,c,d));
27     flag=max(flag,Check(a,b,d));
28     flag=max(flag,Check(b,c,d));
29     if(flag==1) cout<<"TRIANGLE"<<endl;
30     else if(!flag) cout<<"SEGMENT"<<endl;
31     else cout<<"IMPOSSIBLE"<<endl;
32 }
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 #define maxn 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int n,m;
13 char flag;
14 string str[105];
15 map<char,int>mp;
16 
17 int dir[4][2]={0,1,1,0,0,-1,-1,0};
18 void Check(int x,int y){
19     for(int i=0;i<4;i++){
20         int xx=x+dir[i][0];
21         int yy=y+dir[i][1];
22         if(xx>=0&&xx<n&&yy>=0&&yy<m){
23             if(str[xx][yy]!='.'&&str[xx][yy]!=flag)
24                 mp[str[xx][yy]]=1;
25         }
26     }
27 }
28 
29 int main(){
30     #ifndef ONLINE_JUDGE
31         freopen("1.txt","r",stdin);
32     #endif
33     cin>>n>>m>>flag;
34     for(int i=0;i<n;i++) cin>>str[i];
35     for(int i=0;i<n;i++){
36         for(int j=0;j<m;j++){
37             if(str[i][j]==flag) Check(i,j);
38         }
39     }
40     cout<<mp.size()<<endl;
41 }
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 maxn 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int n;
13 
14 int a[100005];
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18         freopen("1.txt","r",stdin);
19     #endif
20     int ans1=0,ans2=0;
21     cin>>n;
22     for(int i=1;i<=n;i++){
23         cin>>a[i];
24     }
25     if(n==1){
26         cout<<"1 0"<<endl;
27         return 0;
28     }
29     int L=1,R=n;
30     while(L<=R){
31         if(ans1<=ans2)
32             ans1+=a[L++];
33         else{
34             ans2+=a[R--];
35         }
36     }
37     L--;
38     R++;
39     cout<<L<<" "<<n-R+1<<endl;
40 
41 }
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 #define maxn 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 int n,a,b;
13 int h[25];
14 vector<int>ve,V;
15 int ans=99999999;
16 
17 void dfs(int pos,int co){
18     if(co>=ans) return;
19     if(pos==n){
20         if(h[pos]<0){
21             ans=co;
22             V=ve;
23         }
24         return;
25     }
26     for(int i=0;i<=max(h[pos-1]/b+1,max(h[pos]/a+1,h[pos+1]/b+1));i++){
27         if(h[pos-1]<b*i){
28             h[pos-1]-=b*i;
29             h[pos+1]-=b*i;
30             h[pos]-=a*i;
31             for(int j=0;j<i;j++) ve.push_back(pos);
32             dfs(pos+1,co+i);
33             for(int j=0;j<i;j++) ve.pop_back();
34             h[pos-1]+=b*i;
35             h[pos+1]+=b*i;
36             h[pos]+=a*i;
37         }
38     }
39 }
40 
41 int main(){
42     #ifndef ONLINE_JUDGE
43         freopen("1.txt","r",stdin);
44     #endif
45     std::ios::sync_with_stdio(false);
46     cin>>n>>a>>b;
47     for(int i=1;i<=n;i++) cin>>h[i];
48     dfs(2,0);
49     cout<<ans<<endl;
50     for(int i=0;i<V.size();i++){
51         cout<<V[i]<<" ";
52     }
53     cout<<endl;
54 }
View Code

 

E

可以用set或线段树找区间最大最小值,然后不断枚举区间

 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 maxn 1000010
 7 typedef long long ll;
 8 /*#ifndef ONLINE_JUDGE
 9         freopen("1.txt","r",stdin);
10 #endif */
11 
12 ll n;
13 multiset<ll>se;
14 ll a[100005];
15 
16 int main(){
17     #ifndef ONLINE_JUDGE
18         freopen("1.txt","r",stdin);
19     #endif
20     ll k;
21     cin>>n>>k;
22     for(int i=1;i<=n;i++){
23         cin>>a[i];
24     }
25     ll L=1;
26     ll Max=0;
27     ll tou,wei;
28     for(int i=1;i<=n;i++){
29         se.insert(a[i]);
30         tou=*se.begin();
31         wei=*se.rbegin();
32         while(abs(tou-wei)>k){
33             se.erase(se.find(a[L++]));
34             tou=*se.begin();
35             wei=*se.rbegin();
36         }
37         ll tmp=se.size();
38         Max=max(Max,tmp);
39     }
40     se.clear();
41     vector<pair<int,int> >ve;
42     L=1;
43     for(int i=1;i<=n;i++){
44         se.insert(a[i]);
45         tou=*se.begin();
46         wei=*se.rbegin();
47         while(abs(tou-wei)>k){
48             se.erase(se.find(a[L++]));
49             tou=*se.begin();
50             wei=*se.rbegin();
51         }
52         if(se.size()==Max){
53             ve.push_back(make_pair(L,i));
54         }
55     }
56     cout<<Max<<" "<<ve.size()<<endl;
57     for(int i=0;i<ve.size();i++){
58         cout<<ve[i].first<<" "<<ve[i].second<<endl;
59     }
60 }
View Code

 

posted on 2019-02-02 17:03  Fighting_sh  阅读(159)  评论(0编辑  收藏  举报

导航