【Codeforces Round】 #431 (Div. 2) 题解
Codeforces Round #431 (Div. 2)
1 second
256 megabytes
standard input
standard output
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
3
1 3 5
Yes
5
1 0 1 5 1
Yes
3
4 3 1
No
4
3 9 9 3
No
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
题目大意:给一个序列,要求分成奇数个首位都是奇数且长度为奇数的序列
试题分析:(官方题解) div-2第一题不要想复杂,因为偶数个奇数为偶数,奇数个奇数为奇数的原则,所以只需判断首位是否是奇数且长度为奇数即可。
(我的题解)想复杂了,dp[i][0]表示前i个已经分配完了(包括i),分了偶数段
dp[i][1]表示前i个已经分配完了(包括i),分了奇数段
转移就是 dp[i][0]=1 (dp[i-j][1]==true&&a[i-j+1]%2==1&&j%2==1)
dp[i][1]=1 (dp[i-j][0]==true&&a[i-j+1]%2==1&&j%2==1)
代码:
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; #define LL long long inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF=9999999;
const int MAXN=100000;
int N; int a[MAXN+1];
bool dp[MAXN+1][2]; int main(){
N=read();
for(int i=1;i<=N;i++){
a[i]=read();
}
dp[0][0]=true;
for(int i=1;i<=N;i++){
if(a[i]%2==0) continue;
for(int j=1;j<=i;j+=2)
if(a[i-j+1]%2!=0&&dp[i-j][0]) {dp[i][1]=true;break;}
for(int j=1;j<=i;j+=2)
if(a[i-j+1]%2!=0&&dp[i-j][1]) {dp[i][0]=true;break;}
}
if(dp[N][1]){puts("Yes");}
else puts("No");
return 0;
}
1 second
256 megabytes
standard input
standard output
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
5
7 5 8 6 9
Yes
5
-1 -2 0 0 -5
No
5
5 4 3 2 1
No
5
1000000000 0 0 0 0
Yes
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
题目大意:有N个点,每个点坐标为(i,yi),要求用两条且必用两条平行线穿过所有点,问是否可行。
试题分析:因为一开始理解错了题意,所以最后一直顺着复杂的思路写了QAQ
其实可以想到,只需要枚举两个点,其y差值作为斜率,然后看是否可行就可以了。
代码:
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; #define LL long long inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF=9999999;
const int MAXN=100000; int N;
int a[MAXN+1];
bool judge(double dis){
int fir=-1;
for(int i=2;i<=N;i++){
if((i-1)*dis==a[i]-a[1]) continue;
if(fir==-1) fir=i;
else if((i-fir)*dis!=a[i]-a[fir]) return false;
}
if(fir!=-1) return true;
return false;
} int main(){
N=read();
for(int i=1;i<=N;i++) a[i]=read();
if(judge(a[2]-a[1])||judge((a[3]-a[1])/2.0)||judge(a[3]-a[2])){
puts("Yes"); return 0;
}
puts("No");
return 0;
}
1 second
256 megabytes
standard input
standard output
From beginning till end, this message has been waiting to be conveyed.
For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:
- Remove any two elements s and t from the set, and add their concatenation s + t to the set.
The cost of such operation is defined to be
, where f(s, c) denotes the number of times character c appears in string s.
Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.
The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.
Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.
Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.
12
abababab
3
codeforces
For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:
- {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;
- {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;
- {"abab", "a", "b", "a", "b"}, with a cost of 1;
- {"abab", "ab", "a", "b"}, with a cost of 0;
- {"abab", "aba", "b"}, with a cost of 1;
- {"abab", "abab"}, with a cost of 1;
- {"abababab"}, with a cost of 8.
The total cost is 12, and it can be proved to be the minimum cost of the process.
题目大意:要构造一个字符串(小写字母),一开始字符串中的每个字符一行,要合并这些字符,使得完全合并后的价值为N。
试题分析:其实想想还是挺简单的,发现无论什么顺序最后每个字符出现次数相同的字符串都会的出来一样的结果。
有了这个结论就很好做了,可以发现连续k个对于答案的贡献是k*(k-1)/2 ( (1+(k-1))*(k-1)/2 )
预处理一下sum(1..i),然后由剩下N的值二分一下,不必担心超过26个字符
代码:
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; #define LL long long inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF=9999999;
const int MAXN=100000; int N;
int a[MAXN+1];
int tmp; int num[MAXN+1]; int main(){
N=read();
if(!N){
puts("ab");
return 0;
}
for(int i=1;i<=10000;i++) a[i]=a[i-1]+i;
while(N){
int k=lower_bound(a+1,a+10001,N)-a;
if(a[k]!=N) k--;
N-=a[k];
num[tmp]=k+1;
++tmp;
}
for(int i=0;i<tmp;i++) {
for(int j=1;j<=num[i];j++)
printf("%c",'a'+i);
}
return 0;
}
【Codeforces Round】 #431 (Div. 2) 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
随机推荐
- oracle直接读写ms sqlserver数据库(一)如何下载oracle database gateway for sqlserver
想从Oracle实时同步数据到Ms Sqlserver,需要在Oracle里面直连Sqlserver进行数据的读写,可以在Oracle服务器上安装oracle database gateway for ...
- TypeScript系列 - 什么是TypeScript
看了很多关于TypeScript的文章,总体说来没有很好的,一个系统的学习TypeScript的资源. 接下来,我将给大家带来TypeScript的系列,让你和我一样,一步一步的学习TypeScrip ...
- jmeter 使用问题
问题1:导入脚本失败,提示 解决:没有安装JMemter plugins manager插件,具体安装参考http://www.cnblogs.com/cxx1/p/7883820.html,第二步.
- FC105 FC106 Scale功能块使用说明
有一点不明白,这个跟传感器本身的分辨率什么关系? 为什么定死 极性和非极性的值是7648 和27648 FC105是处理模拟量(1~5V.4~20MA等信号)输入的功能块: 其中管脚的定义如下:IN- ...
- AWS Add Key Pair to Elastic Beanstalk Instance 给EB实例加密钥
Go to Elastic Beanstalk -> Configuration -> Security -> Virtual machine permissions -> E ...
- PermissionDispatcher 运行时权限框架
第一步在app的build.gradle文件中添加: dependencies { // PermissionDispatcher 框架的使用 implementation 'com.github.h ...
- es6 ...克隆与函数深度克隆
es6的...运算, 可以进行一层的深度克隆; 在多层的情况下,不要用这种啊. 用深度克隆函数,或者JSON.parse(JSON.stringify(obj)),但json方式要求不能有属性值是函数 ...
- workerman 安装event 扩展
2018年7月31日10:07:47 一些小技巧 命令行直接运行PHP代码 php -r "phpinfo();" 交互模式运行PHP php -a PHP脚本作为shell脚本运 ...
- windows redis 自动启动
start.bat D: D:\dev\redis- redis-server.exe redis.conf redis.vbs createobject( 之后,把 start.bat 放在redi ...
- Go并发示例-Pool
https://mp.weixin.qq.com/s/MBY6l5VxrFPJ4AA8nGeQUQ <Go语言实战>笔记(十六) | Go并发示例-Pool 飞雪无情 异步图书 2017- ...