A. Doremy‘s Paint 3

今天第一次打CF,不过鼠鼠被气死了

先说说战况,今天一发没A(赛场上),生活真是无奈,废物女友真是一点用没有

心里也很烦,什么压力都自己扛着。每天想尝试改变什么,又被现实掣肘,或许抛弃掉所有愿望回炉重造才适合我吧。

题面就不粘贴了,给个图片和链接吧,粘贴效果不好

Problem - A - Codeforces

 输入样例

5
2
8 9
3
1 1 2
4
1 1 4 5
5
2 3 3 3 3
4
100000 100000 100000 100000

输出样例

Yes
Yes
No
No
Yes

这一题怎么分析呢,重点是从等式入手,应该要能看出

b1=b3=b5=...b2n-1

b2=b4=b6=...b2n

这两条信息,这说明给出的数字只能是两种

如果两种数的 数量相差不超过一则可以组成good array

具体的我们创建map<int,int>来存储数据计数和判断种类数

使用最值函数取出极值判断即可

#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<string> 
#include<string.h> 
using namespace std;
#define IOO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//const int maxLine=5000+10;
const int maxLine=100+10;
//#define DEBUG true
//int n,m,k;

int arr[maxLine];
//调用可以进行重定向 
void initRedict(){
	#ifdef DEBUG
	cout<<"执行重定向"<<endl; 
	//重定向输入	
	freopen("../redict/demo/demo_in.txt","r",stdin); 
	//重定向输出 覆写 
//	freopen("../redict/demo/demo_out.txt","w",stdout); 
	
	#endif
} 
// 调用可以取消重定向 
void breakEnd(){
	#ifdef DEBUG
	fclose(stdin);
//	fclose(stdout); 
	#endif 
}
bool cmp(const pair<int,int>&a,const pair<int,int>&b){
	return a.second<b.second;
}
int temp;
int main(){
//	initRedict();
	IOO;
	int n;
	cin>>n;
	map<int,int> mymap;
	for(int i=0;i<n;i++){
		int nums;
		cin>>nums;
		mymap.clear();
		
		for(int j=0;j<nums;j++){
			cin>>temp;
			mymap[temp]++;
		}
		if (mymap.size()==1) cout<<"Yes";
		else if (mymap.size()>=3) cout<<"No";
		else {
			int minValue=min_element(mymap.begin(),mymap.end(),cmp)->second;
			int maxValue=max_element(mymap.begin(),mymap.end(),cmp)->second;
			if (abs(minValue-maxValue)<=1) cout<<"Yes";
			else cout<<"No";
		}
		cout<<endl;
	} 
	 
	return 0;
} 

我感觉这个代码是逻辑上最简洁的了

下面也贴一下赛场写的假题代码(因为没看出来只会有两种数字才合法这一规律qwq)

#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<string> 
#include<string.h> 
using namespace std;
#define IOO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//const int maxLine=5000+10;
const int maxLine=100+10;
//#define DEBUG true
int n,m,k;
// 拖堂的班级的人数 
int normalNums=0;
int arr[maxLine];
//调用可以进行重定向 
void initRedict(){
	#ifdef DEBUG
	cout<<"执行重定向"<<endl; 
	//重定向输入	
	freopen("../redict/demo/demo_in.txt","r",stdin); 
	//重定向输出 覆写 
//	freopen("../redict/demo/demo_out.txt","w",stdout); 
	
	#endif
} 
// 调用可以取消重定向 
void breakEnd(){
	#ifdef DEBUG
	fclose(stdin);
//	fclose(stdout); 
	#endif 
}

inline bool check(int arr[maxLine],int len){
	int initNums=arr[0]+arr[1];
	for(int i=0;i<len-1;i++){
		if (arr[i]+arr[i+1]!=initNums){
			return false;
		}
	} 
	return true;
} 
int main(){
//	initRedict();
	IOO;
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		int nums;
		cin>>nums;
		memset(arr,sizeof(arr),0);
		for(int j=0;j<nums;j++){
			cin>>arr[j];
		}
		sort(arr,arr+nums);
		long long sum=0;
		do{
			if (check(arr,nums)){
				flag=true;
				break;
			};
			sum++;
		}while(next_permutation(arr,arr+nums));
		if (flag) cout<<"Yes";
		else cout<<"No";
		cout<<endl;
	} 
	 
	return 0;
} 

全排列狠狠超市,记录一下自己犯蠢写假题写的代码,方便后面回来取笑自己

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JSU_曾是此间年少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值