SUM_ACM-Codeforces Round 941 (Div. 2)
- A
Card Exchange
https://codeforces.com/contest/1966/problem/A
思路:找规律,如果b>a,输出a,如果a中有大于等于b个数,输出b-1即可,如果a中小于b个数输出a。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
int v[101];
int main (){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
while(n--){
memset(v,0,sizeof v);
int res=0;
int a,b;
cin>>a>>b;
for(int i=1;i<=a;i++){
int c;
cin>>c;
v[c]++;
res=max(res,v[c]);
}
if(a<b){
cout<<a<<endl;
}else
{
if(res<b)
cout<<a<<endl;
else
cout<<b-1<<endl;
}
}
}
- B
Rectangle Filling
https://codeforces.com/contest/1966/problem/B
思路:找出不可能的条件为:最上层和最下层不同输出为NO(这里最上层和最下层中的所有元素相同)。
代码如下:
点击查看代码
#include <bits/stdc++.h>
using namespace std;
char mp[502][502];
int main (){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
while(n--){
memset(mp,0,sizeof mp);
int pd1=0;
int pd11=0;
int pd00=0;
int pd0=0;
int pd33=0;
int pd3=0;
int pd4=0;
int pd44=0;
int a,b;
cin>>a>>b;
for(int i=1;i<=a;i++){
for(int j=1;j<=b;j++){
cin>>mp[i][j];
}
}
for(int j=1;j<=b;j++)
{
if(mp[1][j]=='B')
pd0++;
}
for(int j=1;j<=b;j++)
{
if(mp[1][j]=='W')
pd1++;
}
for(int j=1;j<=b;j++)
{
if(mp[a][j]=='B')
pd00++;
}
for(int j=1;j<=b;j++)
{
if(mp[a][j]=='W')
pd11++;
}
for(int j=1;j<=a;j++)
{
if(mp[j][1]=='B')
pd3++;
}
for(int j=1;j<=a;j++)
{
if(mp[j][1]=='W')
pd4++;
}
for(int j=1;j<=a;j++)
{
if(mp[j][b]=='B')
pd33++;
}
for(int j=1;j<=a;j++)
{
if(mp[j][b]=='W')
pd44++;
}
if((pd1==b&&pd00==b)||(pd0==b&&pd11==b)||(pd3==a&&pd44==a)||(pd4==a&&pd33==a))
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}