当前位置: 首页 > news >正文

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 DEBUGcout<<"执行重定向"<<endl; //重定向输入	freopen("../redict/demo/demo_in.txt","r",stdin); //重定向输出 覆写 
//	freopen("../redict/demo/demo_out.txt","w",stdout); #endif
} 
// 调用可以取消重定向 
void breakEnd(){#ifdef DEBUGfclose(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 DEBUGcout<<"执行重定向"<<endl; //重定向输入	freopen("../redict/demo/demo_in.txt","r",stdin); //重定向输出 覆写 
//	freopen("../redict/demo/demo_out.txt","w",stdout); #endif
} 
// 调用可以取消重定向 
void breakEnd(){#ifdef DEBUGfclose(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;
} 

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

http://www.lryc.cn/news/210226.html

相关文章:

  • 深度学习_1 介绍;安装环境
  • Python基础入门例程19-NP19 列表的长度(列表)
  • LeetCode 2558. 从数量最多的堆取走礼物
  • 【JVM】字节码文件的组成部分
  • STM32 TIM(四)编码器接口
  • 力扣第56题 合并区间 c++ 贪心
  • php 日期
  • 食物链解读
  • Day10配置文件日志多线程
  • leetcode:1154. 一年中的第几天(python3解法)
  • 竞赛 深度学习图像修复算法 - opencv python 机器视觉
  • flutter升级+生成drift文件
  • [AUTOSAR][诊断管理][ECU][$34] 下载请求
  • C 标准库 - <errno.h>和<float.h>详解
  • 对于如何学习的一点思考
  • Ensemble Methods集成学习大比拼:性能、应用场景和可视化对比总结
  • 【2024秋招】2023-9-16 贝壳后端开发二面
  • SpringCloud 微服务全栈体系(七)
  • SAP ABAP 报表输出成 excel 统计图形 (RFC : GFW_PRES_SHOW_MULT)
  • 微信小程序如何获取地理位置
  • 计算机网络相关硬件介绍
  • Megatron-LM GPT 源码分析(三) Pipeline Parallel分析
  • Python---使用turtle模块+for循环绘制五角星---利用turtle(海龟)模块
  • Python的比较运算符查询表
  • C/C++面试常见问题——const关键字的作用和用法
  • Vue3.3指北(四)
  • vue如何使用路由拦截器
  • Docker 深度清除镜像缓存 (overlay2)
  • 刷题笔记(第三天)
  • Linux常用命令——chown命令