Codeforces Round #575 (Div. 3) B. Odd Sum Segments 、C Robot Breakout
B题题意:
给你n个数,让你把这n个数分成k个段(不能随意调动元素位置)。你需要保证这k个段里面所有元素加起来的和是一个奇数。问可不可以这样划分成功。如果可以打印YES,之后打印出来是从哪里开始断开的。
否则打印出NO
题解:
加上奇数可以使和的性质改变,原来使偶数则变为奇数,奇数则变为偶数。加上一个偶数就不会有这样的变化。所以第一步就找出来有多少个奇数。因为要保证k个段的和都为奇数,所以每个段得先有一个奇数
剩下来的奇数数量如果是偶数那就不影响,这样就可以成功划分。如果是奇数那就划分不成功
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<map>
6 #include<math.h>
7 using namespace std;
8 typedef long long ll;
9 const int maxn=2e5+5;
10 const int mod=26;
11 const int block=300;
12 int v[maxn];
13 int main()
14 {
15 int t;
16 scanf("%d\n",&t);
17 while(t--)
18 {
19 int n,m,sum=0,a;
20 scanf("%d%d",&n,&m);
21 for(int i=1;i<=n;++i)
22 {
23 scanf("%d",&v[i]);
24 if(v[i]%2)
25 sum++;
26 }
27 sum-=m;
28 if(sum<0)
29 printf("NO\n");
30 else if(sum==0 || sum%2==0)
31 {
32 //sum/=2;
33 printf("YES\n");
34 int i;
35 if(sum==0) i=0;
36 else i=1;
37 if(sum!=0)
38 for(i;i<=n;++i)
39 {
40 if(v[i]%2)
41 {
42 sum--;
43 if(sum==0)
44 break;
45 }
46 }
47 for(i+=1;i<=n;++i)
48 {
49 if(m==1)
50 {
51 printf("%d\n",n);
52 break;
53 }
54 if(v[i]%2)
55 {
56 printf("%d ",i),m-=1;
57 }
58 }
59 }
60 else printf("NO\n");
61 }
62 return 0;
63 }
C题题意:
给你n个机器人,这n个机器人有四个移动方向,但是有可能它的中枢坏了导致不能向某个方向移动。现在你需要找到一个坐标,机器人得到这个坐标会来到这里,但是也有某些方向损坏的机器人来不了
所以你需要找出来有没有能让所有机器人都到达这里的一个坐标。能找出来的话就先打印一个“1”再打印出这个坐标,否则打印出0
题解:
找出来所有机器人可移动区间,再让它们取并集就可以了
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<map>
6 #include<math.h>
7 using namespace std;
8 typedef long long ll;
9 const int maxn=1e5;
10 const int mod=26;
11 const int block=300;
12 struct shudui
13 {
14 int xmin,xmax,ymin,ymax,x,y;
15 } m[maxn+5];
16 int main()
17 {
18 int t;
19 scanf("%d",&t);
20 while(t--)
21 {
22 int xmin=-maxn,xmax=maxn,ymin=-maxn,ymax=maxn,flag=0;
23 int n,x1,x2,x3,x4,x,y;
24 scanf("%d",&n);
25 for(int i=1; i<=n; ++i)
26 {
27 scanf("%d%d%d%d%d%d",&x,&y,&x1,&x2,&x3,&x4);
28 m[i].x=x;
29 m[i].y=y;
30 if(!flag)
31 {
32 if(x1)
33 m[i].xmin=-maxn;
34 else m[i].xmin=x;
35 if(x2)
36 m[i].ymax=maxn;
37 else m[i].ymax=y;
38 if(x3)
39 m[i].xmax=maxn;
40 else m[i].xmax=x;
41 if(x4)
42 m[i].ymin=-maxn;
43 else m[i].ymin=y;
44 if(xmin>m[i].xmax || xmax<m[i].xmin || ymin>m[i].ymax || ymax<m[i].ymin)
45 {
46 flag=1;
47 }
48 else
49 {
50 xmin=max(xmin,m[i].xmin);
51 xmax=min(xmax,m[i].xmax);
52 ymin=max(ymin,m[i].ymin);
53 ymax=min(ymax,m[i].ymax);
54 }
55 }
56 }
57 if(!flag)
58 {
59 printf("1 %d %d\n",xmin,ymin);
60 }
61 else printf("0\n");
62 }
63 return 0;
64 }
Codeforces Round #575 (Div. 3) B. Odd Sum Segments 、C Robot Breakout的更多相关文章
- Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)
B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard in ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #575 (Div. 3)
本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...
- Codeforces Round #575 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...
- Codeforces Round #646 (Div. 2) A. Odd Selection(数学)
题目链接:https://codeforces.com/contest/1363/problem/A 题意 判断是否能从 $n$ 个数中选 $x$ 个数加起来和为奇数. 题解 首先 $n$ 个数中至少 ...
- Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)
传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...
随机推荐
- If you see someone without smile
If you see someone without smile, give them one of yours. 难怪我每次和不认识的人说话都放肆大笑.
- Linux Bash Shell常用快捷键
Linux Bash Shell常用快捷键 table { margin: auto } 快捷键 功能 tab 补全 ctrl + a 光标回到命令行首 ctrl + e 光标回到命令行尾 ctrl ...
- JAVA之JDBC数据库连接池总结篇
JDBC数据库连接池 一.JDBC数据库连接池的必要性 二.数据库连接池技术 三.多种开源的数据库连接池 3.1 C3P0数据库连接池 3.2 DBCP数据库连接池 3.3 Druid(德鲁伊)数据库 ...
- 敏感信息泄露 - Pikachu
概述: 由于后台人员的疏忽或者不当的设计,导致不应该被前端用户看到的数据被轻易的访问到. 比如:---通过访问url下的目录,可以直接列出目录下的文件列表;---输入错误的url参数后报错信息里面包含 ...
- XEE - Pikachu
概述 XXE -"xml external entity injection"既"xml外部实体注入漏洞".概括一下就是"攻击者通过向服务器注入指定的 ...
- mysql—make_set函数
使用格式:MAKE_SET(bits,str1,str2,-) 1 返回一个设定值(含子字符串分隔字符串","字符),在设置位的相应位的字符串.str1对应于位0,str2到第1位 ...
- linux多路径(multipath)
https://www.itread01.com/articles/1475909423.html
- 1.8V升3V芯片,1.8V升3.3V升压芯片方案
两节干电池由于耗电量电压会降低,无法长期稳定的输出3V或者3.3V供电,直接两节干电池会供电电压不稳,影响后面电路稳定.两节干电池的供电电压在1.8V-3.2V左右 1.8V升3V升压芯片方案, 如P ...
- Java多线程基础知识笔记(持续更新)
多线程基础知识笔记 一.线程 1.基本概念 程序(program):是为完成特定任务.用某种语言编写的一组指令的集合.即指一段静态的代码,静态对象. 进程(process):是程序的一次执行过程,或是 ...
- 深度学习DeepLearning技术实战研修班
深度学习DeepLearning(Python)实战培训班 时间地点: 2020 年 12 月 18 日-2020 年 12 月 21日 (第一天报到 授课三天:提前环境部署 电脑测试) 一.培训方式 ...