A. Odds and Ends

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
  1. 3
    1 3 5
output
  1. Yes
input
  1. 5
    1 0 1 5 1
output
  1. Yes
input
  1. 3
    4 3 1
output
  1. No
input
  1. 4
    3 9 9 3
output
  1. 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.

题意:给定一数组,判断是否可以分成奇数个组,每组个数是奇数,每组的首尾都为奇数。

分析:偶数长度不可能,奇数长度无论怎么分,首尾必须都为奇数,否则不可能,思维题!

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn = ;
  6.  
  7. int a[maxn];
  8.  
  9. int main()
  10. {
  11. int n;
  12. scanf("%d",&n);
  13.  
  14. for(int i = ; i < n; i++)
  15. scanf("%d",&a[i]);
  16.  
  17. if(n%==) {
  18. if(a[]%==||a[n-]%==)
  19. puts("No");
  20. else puts("Yes");
  21. }
  22. else {
  23. puts("No");
  24. }
  25.  
  26. return ;
  27. }
B. Tell Your World

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
  1. 5
    7 5 8 6 9
output
  1. Yes
input
  1. 5
    -1 -2 0 0 -5
output
  1. No
input
  1. 5
    5 4 3 2 1
output
  1. No
input
  1. 5
    1000000000 0 0 0 0
output
  1. 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 个点的坐标,判断是否所有的点,都在两条不重合的平行线上。

分析:

计算几何很少接触,但是一般CF的计算几何都是考思维,感觉很复杂,情况很多!

看了大牛的思路,确实厉害。

因为只存在两条平行直线,枚举这平行直线,平行直线可以通过ab,bc,ac,另一个点就在另一条平行的直线上。

这样将所有点分为了两个部分,其中另一个部分,要么只有一个点,要么在一条直线上,并且平行。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn = ;
  6.  
  7. typedef long long ll;
  8. int n;
  9.  
  10. struct Node {
  11. ll x,y;
  12. } nodes[maxn],pp[maxn];
  13.  
  14. ll cc(Node a,Node b,Node c) {
  15. return (b.y-a.y)*(c.x-b.x) - (c.y-b.y)*(b.x-a.x);
  16. }
  17.  
  18. bool check() {
  19. int cnt=;
  20. for(int i=; i<=n; i++)
  21. if(cc(nodes[],nodes[],nodes[i])!=)
  22. pp[++cnt]=nodes[i];
  23.  
  24. for(int i=; i<=cnt; i++)
  25. if(cc(pp[],pp[],pp[i])!=)
  26. return ;
  27. Node ta,tb,tc;
  28. ta.x=nodes[].x-nodes[].x,ta.y=nodes[].y-nodes[].y;
  29. tb.x=pp[].x-pp[].x,tb.y=pp[].y-pp[].y;
  30. tc.x=tc.y=;
  31. return cnt<||cc(tc,ta,tb)==;
  32. }
  33.  
  34. int main() {
  35. scanf("%d",&n);
  36.  
  37. for(int i = ; i <= n; i++) {
  38. scanf("%I64d",&nodes[i].y);
  39. nodes[i].x = i;
  40. }
  41.  
  42. int ff = ;
  43. for(int i=; i<=n&&!ff; i++)
  44. if(cc(nodes[i-],nodes[i-],nodes[i])!=)
  45. ff=;
  46. if(!ff) {
  47. printf("NO\n");
  48. return ;
  49. }
  50. if(check()) {
  51. printf("YES\n");
  52. return ;
  53. }
  54. swap(nodes[],nodes[]);
  55. if(check()) {
  56. printf("YES\n");
  57. return ;
  58. }
  59. swap(nodes[],nodes[]);
  60. if(check()) {
  61. printf("YES\n");
  62. return ;
  63. }
  64. printf("NO\n");
  65. return ;
  66.  
  67. return ;
  68. }
C. From Y to Y

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 cappears 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
  1. 12
output
  1. abababab
input
  1. 3
output
  1. 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.

题意:给定一个整数 k ,求构造一个字符串,字符串由单个多重集合的字母拼起来,每次连接两个字符串,都有代价,总代价题目中有。

分析:

策略是:全部都与单字符拼起来。接近答案时,换一个字符重头来。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int n;
  9. scanf("%d",&n);
  10.  
  11. string s = "";
  12. if(n==) {
  13. cout<<"a"<<endl;
  14. }
  15. else {
  16. char c = 'a';
  17. while(n) {
  18. int sum = ;
  19. int i = ;
  20. for(i = ; sum <=n; i++) {
  21. sum +=i;
  22. }
  23.  
  24. n -=(sum-i+);
  25. for(int j = ; j<i-;j++) {
  26. s +=c;
  27. }
  28. c++;
  29.  
  30. }
  31. cout<<s<<endl;
  32. }
  33.  
  34. return ;
  35. }

总的来说,感觉思维上和大佬们还是有很大的差距,要继续努力才行~~~

Codeforces Round #431 (Div. 2)的更多相关文章

  1. Codeforces Round #431 (Div. 1)

    A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #431 (Div. 2) C. From Y to Y

    题目: C. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #431 (Div. 2) C

    From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...

  4. 【Codeforces Round #431 (Div. 1) D.Shake It!】

    ·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意:     一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...

  5. 【Codeforces Round 431 (Div. 2) A B C D E五个题】

    先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意:      输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...

  6. Codeforces Round #431 (Div. 2) B. Tell Your World

    B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song

    给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...

  8. 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y

    题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...

  9. Codeforces Round #431 (Div. 2) B

    Connect the countless points with lines, till we reach the faraway yonder. There are n points on a c ...

随机推荐

  1. RedisClient 连接redis 提示 ERR Client sent AUTH, but no password is set

  2. Docker的安装和镜像管理并利用Docker容器实现nginx的负载均衡、动静分离

    Docker的安装 一.Docker的概念 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化 ...

  3. 1.2 js基础

    1.onchange    99%用到select上边. 2.js是干什么的,修改css样式和属性   3.选项卡步骤   1.获取元素 2.循环给按钮加自定义属性 3.循环给按钮加事件   4.封装 ...

  4. Linux文本处理工具

    Linux文本处理工具 Linux中熟练的使用文本处理工具非常的重要, 因为Linux在设计的时候是采用一切皆文件的哲学的, 甚至连计算机中的配置也都使用伪文件系统来表示, 要查询里面的内容就是对文件 ...

  5. SpringBoot | 第三十章:Spring-data-jpa的集成和使用

    前言 在前面的第九章:Mybatis-plus的集成和使用章节中,介绍了使用ORM框架mybatis-plus进行数据库的访问.今天,我们来简单学习下如何使用spring-data-jpa进行数据库的 ...

  6. 吴恩达《Machine Learning Yearning》总结(31-40章)

    31.解读学习曲线:其他情况 下图反映了高方差,通过增加数据集可以改善. 下图反映了高偏差和高方差,需要找到一种方法来同时减少方差和偏差. 32.绘制学习曲线 情况:当数据集非常小时,比如只有100个 ...

  7. JQuery选择器——《锋利的JQuery》

    刚学CSS的时候我们已经接触了选择器,其实就是按照一定的规则选择出来我们想要获取到的元素.在这里,既然选择了用jQuery选择器,首先来谈谈JQuery选择器的优势: 1.简洁的写法:$()函数在很多 ...

  8. Java流和文件

    File类:java.io包下与平台无关的文件和目录 java可以使用文件路径字符串来创建File实例,文件路径可以是绝对路径,也可以是相对路径,默认情况下,相对路径是依据用户工作路径,通常就是运行J ...

  9. SQLServer 2016 Express 安装部署,并配置支持远程连接

    在项目中需要用到SQLServer,于是安装部署了SQLServer,部署的过程中遇到了一下问题,记录一下以便之后遇到同样问题能快速解决. 一.安装包下载 首先下载必要的安装包: 1.SQLServe ...

  10. 邓俊辉数据结构学习-7-BST

    二叉搜索树(Binary-Search-Tree)--BST 要求:AVL树是BBST的一个种类,继承自BST,对于AVL树,不做太多掌握要求 四种旋转,旋转是BBST自平衡的基本,变换,主要掌握旋转 ...