Codeforces Round #662 (Div. 2)

A

找规律,发现每两个是一样的,表达出来就可以了

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll maxn=2e5+100;
 5 const ll mod=1e9+7;
 6 ll t,n;
 7  
 8 int main(){
 9     //freopen("in.txt","r",stdin);
10     ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
11     cin>>t;
12     while(t--){
13         ll n;
14         cin>>n;
15         cout<<(ll)n/2+1<<endl;
16     }
17     return 0;
18 }

B

我本来是有思路的,而且思路是对的,但是奈何脑抽没有想到怎么存数据。只要维护个数为$2,4,6,8$(记得加上区间)的木条就可以了,然后每次看是否能构成一个正方形和一个矩形。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll maxn=2e5+100;
 5 const ll mod=1e9+7;
 6 typedef pair<ll,ll> P;
 7 ll t,n,m,a[maxn];
 8 map<ll,ll> cn;
 9 ll co[10];
10 int main(){
11     //freopen("in.txt","r",stdin);
12     ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
13     cin>>n;
14     for(int i=0;i<n;i++){
15         cin>>t;
16         cn[t]++;
17     }
18     for(auto i:cn){
19         t=i.second;
20         if(t>=2&&t<4)co[2]++;
21         if(t>=4&&t<6)co[4]++;
22         if(t>=6&&t<8)co[6]++;
23         if(t>=8)co[8]++;
24     }
25     cin>>m;
26     for(int i=0;i<m;i++){
27         char c;
28         cin>>c>>t;
29         if(c=='+'){
30             cn[t]++;
31             if(cn[t]==2) co[2]++;
32             if(cn[t]==4) co[4]++,co[2]--;
33             if(cn[t]==6) co[6]++,co[4]--;
34             if(cn[t]==8) co[8]++,co[6]--;
35         }else{
36             cn[t]--;
37             if(cn[t]==1) co[2]--;
38             if(cn[t]==3) co[4]--,co[2]++;
39             if(cn[t]==5) co[6]--,co[4]++;
40             if(cn[t]==7) co[8]--,co[6]++;
41         }
42         if(co[8]>=1||(co[4]>=2)||co[6]>=2||(co[4]>=1&&co[2]>=2)||(co[6]>=1&&co[2]>=1)||(co[4]>=1&&co[6]>=1)){
43             cout<<"YES"<<endl;
44         }else cout<<"NO"<<endl;
45     }
46     return 0;
47 }

C

啊呀,真的难受,分母的地方写成另外一个变量了,导致分母为$0$,然后$RE$了。其实就是看出现次数最大那个,最终就是往这个里面添加,要先求出来这个最大的出现了多少次,然后再把剩余的尽可能拓宽的放进去,也就是只放最大个数中间的逢,所以就有了答案的表达式(见代码)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll maxn=2e5+100;
 5 const ll mod=1e9+7;
 6 typedef pair<ll,ll> P;
 7 ll t,n,m,a[maxn];
 8 map<ll,ll> cn;
 9 int main(){
10     //freopen("in.txt","r",stdin);
11     ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
12     cin>>t;
13     while(t--){
14         cin>>n;
15         ll maxi=1;
16         for(int i=0;i<n;i++){
17             cin>>a[i];
18             cn[a[i]]++;
19             maxi=max(maxi,cn[a[i]]);
20         }ll cnt=0;
21         for(auto i=cn.begin();i!=cn.end();i++){
22             if(i->second==maxi)cnt++;
23         }
24         if(cn.size()==1) cout<<0<<endl;
25         else cout<<cnt-1+(ll)(n-maxi*cnt)/(maxi-1)<<endl;//血的教训
26         cn.clear();
27     }
28     return 0;
29 }

posted @ 2020-08-08 01:06  Zabreture  阅读(84)  评论(0编辑  收藏  举报