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 ...
随机推荐
- Centos 安装 Node-v12.17.0-linux-x64.tar.gz
wget https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.gz tar -zxf node-v12.17.0-linux-x6 ...
- zabbix客户端安装配置
1.下载,解压并安装zabbixtar zxvf zabbix-2.0.12.tar.gzcd zabbix-2.0.12./configure --prefix=/usr/local/zabbix ...
- show engine innodb status
TRANSACTIONS------------Trx id counter 2003909(当前事务号)Purge done for trx's n:o < 2003905 (清理线程完成到了 ...
- C#数组的 Length 和 Count()
C#数组的 Length 和 Count() C# 数组中 Length 表示数组项的个数,是个属性.而 Count() 也是表示项的个数,是个方法,它的值和 Length 一样.但实际上严格地说, ...
- 利用Numpy求解投资内部收益率IRR
一. 内部收益率和净现值 内部收益率(Internal Rate of Return, IRR)其实要和净现值(Net Present Value, NPV)结合起来讲.净现值指的是某个投资项目给公司 ...
- merge join pg伪代码
Join { get initial outer and inner tuples INITIALIZE do forever { while (outer != inner) { SKIP_TEST ...
- SAP下载文档为乱码
通过事物WE60下载的文档为乱码,主要原因是编码格式的不匹配,通常默认的编码格式为ANSI编码,那么我们需要将源码的编码格式转换成UTF-8,这样问题可以解决了. 附:编码格式介绍 不同的国家和地 ...
- HTML&CSS:构建网站不能不说的那些事儿
很高兴你能看到这个专栏!俗话说得好,相逢即是缘分,没准你和我在上一世也曾有过五百次的回眸,才得此一面.说的有点恶心了,咱还是书归正传,说说这个专栏吧. 这个专栏主要讲的是 HTML 和 CSS 的页面 ...
- 10_1_OS模块
1.常用函数目录 函数名 功能 os.name 指示用户正在使用的工作平台 os.getcwd ( ) 获取当前的工作目录 os.listdir ( ) 返回指定目录下的所有文件和目录名 os.rem ...
- Flask的配置文件加载两种方式
配置文件 1 基于全局变量 2 基于类的方式 配置文件的加载需要将配合文件的相对路径添加到app.config.from_object("文件路径"),类的方式也是一样,需要将类的 ...