Codeforces Round #661 (Div. 3)
A. Remove Smallest
题意:数组是否满足任意i,j保证|ai-aj|<=1,如果都可以满足,输出YES,否则输出NO
思路:直接排序遍历即可
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 #include<queue>
7 #include<vector>
8 #include<set>
9 using namespace std;
10 int main(){
11 int t;
12 scanf("%d",&t);
13 while(t--){
14 int n;
15 scanf("%d",&n);
16 int a[100];
17 for(int i=0;i<n;i++){
18 scanf("%d",&a[i]);
19 }
20 sort(a,a+n);
21 int flag=0;
22 for(int i=1;i<n;i++){
23 if(a[i]-a[i-1]>1){
24 flag=1;
25 break;
26 }
27 }
28 if(flag==0){
29 printf("YES\n");
30 }else{
31 printf("NO\n");
32 }
33 }
34 }
B. Gifts Fixing
题意:两组数a[i],b[i],你可以对两组数的数字进行如下操作:1.加减1;2.同一位置的数一起加减1,则使得a1=a2=a3....=an,并且b1=b2=b3.....=bn,那么需要最少进行多少步
思路:先找出两组数中每组里面最小的那个数,每次循环进行比较a[i]与a[min],再找到a[i]和b[i]最大的那个数,直接算其和
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 #include<queue>
7 #include<vector>
8 #include<set>
9
10 using namespace std;
11 pair<int,int> a[100];
12 int main(){
13 int t;
14 scanf("%d",&t);
15 while(t--){
16 int n;
17 scanf("%d",&n);
18 long long int sum=0;
19 int minn1=1e9,minn2=1e9;
20 for(int i=0;i<n;i++){
21 scanf("%d",&a[i].first);
22 minn1=min(minn1,a[i].first);
23 }
24 for(int i=0;i<n;i++){
25 scanf("%d",&a[i].second);
26 minn2=min(minn2,a[i].second);
27 }
28 sort(a,a+n);
29 for(int i=0;i<n;i++){
30 sum+=max(a[i].second-minn2,a[i].first-minn1);
31 }
32 printf("%lld\n",sum);
33 }
34 }
C. Boats Competition
题意:一组数从中抽取两个数,保证a[1]+b[1]=a[2]+b[2]……=a[k]+b[k],一共最多可以抽取多少组
思路:直接进行统计,抽取的两个数只有两种情况,一种是等差中项是整数的,例如1.2.3;一种是等差中项不是整数的,例如1.2.3.4;直接存储其数值个数,进行循环比较最多,一定注意是取两个数的最小值,不是平均值,并且遍历的时候要从第一个for循环的i入手往前走,不要从1开始走
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 #include<queue>
7 #include<vector>
8 #include<set>
9 using namespace std;
10
11 int main(){
12 int t;
13 scanf("%d",&t);
14 while(t--){
15 int n;
16 scanf("%d",&n);
17 int a[60][2]={0};
18 int numl;
19
20 for(int i=1;i<=60;i++){
21 a[i][0]=i;
22 }
23 for(int i=1;i<=n;i++){
24 scanf("%d",&numl);
25 a[numl][1]++;
26 }
27 int sum=0,num=0;
28 for(int i=1;i<=n;i++){
29 num=0;
30 num+=a[i][1]/2;
31 for(int j=i-1;j>=1&&2*i-j<=n&&2*i-j>i;j--){
32 if(a[2*i-j][1]==0||a[j][1]==0){
33 continue;
34 }else{
35 num+=min(a[j][1],a[2*i-j][1]);
36 }
37 }
38 sum=max(num,sum);
39 }
40 for(int i=1;i<=n;i++){
41 num=0;
42 if(a[i][1]==0||a[i+1][1]==0){
43
44 }else{
45 num+=min(a[i][1],a[i+1][1]);
46 }
47 for(int j=i-1;j>=1&&2*i+1-j<=n&&2*i+1-j>i+1;j--){
48 if(a[j][1]==0||a[2*i+1-j][1]==0){
49 continue;
50 }else{
51 num+=min(a[j][1],a[2*i+1-j][1]);
52
53 }
54 }
55 sum=max(num,sum);
56 }
57 if(n==2){
58 printf("1\n");
59 continue;
60 }else{
61 printf("%d\n",sum);
62 }
63
64 }
65 }
Codeforces Round #661 (Div. 3)的更多相关文章
- Codeforces Round #661 (Div. 3) D、E1 题解
D. Binary String To Subsequences #贪心 #构造 题目链接 题意 给定一个\(01\)串\(s\),完全分割成若干子序列(注意,不要混淆子串与子序列的概念),其中的子序 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- c# DataGirdView动态刷新
using MySql.Data.MySqlClient;using System; using System.Data; using System.Threading; using System.W ...
- Linux+mysql混杂
一.linux 1.linux中给某一文件中批量新增一个内容 先vim进入文件,然后先按ctrl+v 然后选中需要的行数, 在shift+i 写你要添加的东西 然后在按下esc 二,mysql 1.l ...
- python学习8 文件的操作
本文拷贝了on testing 的<python之文件操作:文件的读写>,只做学习之用 python的文件读写通过 一.用open函数 二.对文件读写操作 三.读取文件位置定位 1. op ...
- MIT 6.824拾遗(一)聊聊basic-paxos
前言 The Paxos algorithm, when presented in plain English, is very simple. ------ Lamport,<Paxos Ma ...
- java例题_46 两个字符串拼接问题!
1 /*46 [程序 46 字符串连接] 2 题目:两个字符串连接程序,将两个字符串拼接在一起 3 */ 4 5 /*分析 6 * 两个字符串的拼接方法 7 * concat方式 8 * 当两个量都为 ...
- 学习笔记-vue 打包去#和页面空白问题
文件资源路径是对的,但是页面空白.百度了很久找了一篇文章解决了. 1.vue项目中config文件下index.js中打包配置 build: { // Template for index.html ...
- 什么是 Ansible - 使用 Ansible 进行配置管理
[注]本文译自:https://www.edureka.co/blog/what-is-ansible/ Ansible 是一个开源的 IT 配置管理.部署和编排工具.它旨在为各种自动化挑战提供巨 ...
- ASP.NET Core中使用令牌桶限流
在限流时一般会限制每秒或每分钟的请求数,简单点一般会采用计数器算法,这种算法实现相对简单,也很高效,但是无法应对瞬时的突发流量. 比如限流每秒100次请求,绝大多数的时间里都不会超过这个数,但是偶尔某 ...
- 03.ElementUI源码学习:代码风格检查和格式化配置(ESlint & Prettier)
书接上文.在团队协作中,为避免低级Bug.以及团队协作时不同代码风格对彼此造成的困扰与影响,会预先制定编码规范.使用 Lint工具和代码风格检测工具,则可以辅助编码规范执行,格式化代码,使样式与规则保 ...
- 直接跑day07中现成的代码可能出现的问题
由于前面课程中敲代码可能存在写bug且实战作业没有完成,因此今天直接把资料里的代码拿来用.遇到两个问题 问题1:Cannot find JRE '1.8'. You can specify JRE t ...