Codeforces Round #431 (Div. 2) 

A. Odds and Ends
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.

You can output each letter in any case (upper or lower).

Examples
  input
3
1 3 5
  output
Yes
  input
5
1 0 1 5 1
  output
Yes
  input
3
4 3 1
  output
No
  input
4
3 9 9 3
  output
No
Note

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;
}

 

B. Tell Your World
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

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).

Examples
  input
5
7 5 8 6 9
  output
Yes
  input
5
-1 -2 0 0 -5
  output
No
  input
5
5 4 3 2 1
  output
No
  input
5
1000000000 0 0 0 0
  output
Yes
Note

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;
}
 
C. From Y to Y
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output

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.

Examples
  input
12
  output
abababab
  input
3
  output
codeforces
Note

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) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. 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 题解 直接 ...

  10. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

随机推荐

  1. phpstorm设置篇

    1.设置全局字体编码: File->settings->Editor->File Encodings 进入这个页面后,有个Global Encoding , 默认是 UTF8 ,如果 ...

  2. 对于服务器AdminServer, 与计算机Machine-0相关联的节点管理器无法访问

    控制台启动server时报"对于服务器server-1与计算机machin<!--StartFragment -->对于服务器AdminServer, 与计算机Machine-0 ...

  3. elasticsearch之分词插件使用

    elasticsearch对英文会拆成单个单词,对中文会拆分成单个字.下面来看看是不是这样. 首先测试一下英文: GET /blog/_analyze { "text": &quo ...

  4. css3 属性

    1.css 面试题: css 组成: css 样式组成 规则:选择器+声明块 声明块:css属性+css属性值 2.css 解析规则: 从右往左 3.文字超出省略号显示: 1.元素不是内联块 2.ov ...

  5. 用JS编写个人所得税计算器

    编写 “个人所得税计算器”函数 计算个税的方法: 3500 以下免征 3500 ~ 5000 部分 缴纳 3% 5000 ~ 9000 部分 缴纳 10% 9000 以上部分 缴纳 20% 代码如下: ...

  6. java实现求最大子数组和的逐步显示

    package 最大的子数组和; import java.util.Scanner; public class shuzu { public static int maxArr(int a[]) { ...

  7. oo第三次总结

    一.(1)规格化设计的大致发展历史 20世纪60年代,随着大容量.高速度的计算机出现,以及大量语言的新增和软件的不可靠,爆发了所谓的“软件危机”.而针对这个问题,人们提出了规格化设计的解决方法.通过把 ...

  8. ide phpStorm 配置PHP路径并本地执行PHP脚本

    1.打开设置(File - Settings) 2. 3. 4.到需要执行脚本的文件处,右击 - Run 5.如果本地还未安装PHP,可以下载Xampp,并将PHP目录新增至系统环境变量Path处,重 ...

  9. ListView添加图片文字项

    1)listview 控件 结合 imagelist 控件 实现类似效果. 2)添加 imagelist 控件 images 属性,点击后面的... 添加相应图片. 3)点listview,查看其属性 ...

  10. 2019年春季学期第二周作业 基础作业 请在第一周作业的基础上,继续完成:找出给定的文件中数组的最大值及其对应的最小下标(下标从0开始)。并将最大值和对应的最小下标数值写入文件。 输入: 请建立以自己英文名字命名的txt文件,并输入数组元素数值,元素值之间用逗号分隔。 输出 在不删除原有文件内容的情况下,将最大值和对应的最小下标数值写入文件

    ~~~ include<stdio.h> include<stdlib.h> int main() { FILE*fp; int i=0,max=0,j=0,maxb=0; i ...