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.

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.

问你把长度为n的序列化为奇数开头奇数结尾而且个数是奇数的数列

首先分析偶数,凑两个奇数数列,然后这个子序列个数就又是偶数了

所以只有奇数个符合要求,开头结尾必须是,合并为一个就好了

我错了是因为优先级 判断末位是不是奇数要用 (n&1)==0

#include<bits/stdc++.h>
using namespace std;
int main()
{int n;cin>>n;int a[102];for(int i=1;i<=n;i++)cin>>a[i];int f=0;if(n&1&&a[1]&1&&a[n]&1)f=1;printf("%s",f?"Yes":"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.

 

 这个题嘛就是给你一堆点,让你判断在不在两条平行(不重合)的直线上

我选用前三个点在不在一条直线上,在的话就是其他点还有一条直线

不在的话就分三种情况讨论

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[1005];int n;
bool check()
{int f=-1;LL f1=a[3]-a[2];if(a[2]*2==a[1]+a[3]){for(int i=4; i<=n; i++){if((a[i]-a[1])!=(i-1)*f1){if(f==-1)f=i;else{if((a[i]-a[f])!=(i-f)*f1){return 0;}}}}if(f==-1){return 0;}}else{f=0,f1=a[2]-a[1];for(int i=4; i<=n; i++){if((a[i]-a[1])!=(i-1)*f1&&((a[i]-a[3])!=(i-3)*f1)){f++;break;}}f1=a[3]-a[2];for(int i=4; i<=n; i++){if((a[i]-a[2])!=(i-2)*f1&&((a[i]-a[1])!=(i-1)*f1)){f++;break;}}f1=a[3]-a[1];for(int i=4; i<=n; i++){if(2*(a[i]-a[2])!=(i-2)*f1&&(2*(a[i]-a[1])!=(i-1)*f1)){f++;break;}}if(f==3)return 0;}return 1;
}
int main()
{scanf("%d",&n);for(int i=1; i<=n; i++)scanf("%lld",a+i);if(!check())printf("No\n");else printf("Yes\n");return 0;
}
这个写法好啊

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
ll y[N];
int n;
bool gx(int a,int b,int c,int d)
{return (b-a)*(y[d]-y[c])==(d-c)*(y[b]-y[a]);
}
int check(int d,int f)
{vector<int>V;for(int i=1; i<=n; i++)if(!gx(d,f,f,i))V.push_back(i);if(V.size()==0)return 0;if(V.size()==1)return 1;for(int i=1; i<(int)V.size(); i++)if(!gx(d,f,V[i],V[i-1]))return 0;return 1;
}
int main()
{cin>>n;for(int i=1; i<=n; i++)cin>>y[i];if(check(1,2)||check(2,3)||check(1,3))cout<<"YES";else cout<<"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.

 

 就是贪心构造,合并花费是0,但是连续的某个字母生成的话费是n*(n-1)/2,每次生成最多就好的

#include <bits/stdc++.h>
using namespace std;
int a[500];
int main()
{int k;scanf("%d",&k);for(int i=1;i<450;i++)a[i]=i*(i-1)/2;if(k==0)printf("a");else{int f=0;char c='a';while(k){int pos=lower_bound(a+1,a+450,k)-a;if(a[pos]>k)pos--;for(int i=0;i<pos;i++)printf("%c",c);k-=a[pos];c++;}}return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7465836.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540687.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ping/pong模式_PING的完整形式是什么?

ping/pong模式PING&#xff1a;数据包InterNet Groper (PING: Packet InterNet Groper) In the sector of networking of computers, PING is an abbreviation of Packet InterNet Groper. It is utility software or system software of administration of computer network u…

Gartner: 2017年11大信息安全技术(解读版)

在2017年6月份举办的第23届Gartner安全与风险管理峰会上&#xff0c;Gartner的Fellow——Neil McDonald发布了2017年度的11个最新最酷的信息安全技术&#xff0c;比往年的10大技术多了一项。以往都是通过互联网了解Gartner的各种信息和报告。这次&#xff0c;本人有幸亲临现场&…

博客url什么形式_URL的完整形式是什么?

博客url什么形式URL&#xff1a;统一资源定位符 (URL: Uniform Resource Locator) URL is an abbreviation of Uniform Resource Locator. Uniform Resource Locator which is informally or casually known as a web address is addressed as a resource of the web, which ca…

宝马奥迪工厂模式_宝马的完整形式是什么?

宝马奥迪工厂模式宝马&#xff1a;巴伐利亚汽车公司 (BMW: Bayerische Motoren Werke) BMW is an abbreviation of "Bayerische Motoren Werke". It is a multinational automobile and motorcycle manufacturing company whose headquarter is situated in Munich, …

艾拉物联CEO :物联网时代的到来让安全问题显得尤为突出

产品安全和嵌入式安全的理念一直都很复杂&#xff0c;不过我们至少对它们比较熟悉。但物联网&#xff08;IoT&#xff09;却对“产品”这一理念进行了颠覆&#xff0c;让联网成为了产品定义中不可或缺的一部分。 由此一来&#xff0c;仅在设备层面讨论安全已经远远不够了。不论…

jquery选择器连续选择_JQuery中的选择器

jquery选择器连续选择Its time to write some JQuery now. Do check out the introductory article on JQuery first in case you havent. Before we move to Selectors in JQuery, lets talk a bit about the general syntax first. 现在该写一些JQuery了。 如果没有&#xff…

split注意事项

为什么80%的码农都做不了架构师&#xff1f;>>> 1.特殊字符 “|”&#xff0c;“*”&#xff0c;“^”&#xff0c;"."&#xff0c;“&#xff1a;”&#xff0c;使用此字符作为分割符&#xff0c;必须用\\加以转义 2.同时存在多个特殊字符的时候&#x…

Floyd Warshall算法

Description: 描述&#xff1a; This is a very popular interview problem to find all pair shortest paths in any graph. This problem has been featured in interview rounds of Samsung. 这是一个非常流行的面试问题&#xff0c;用于在任何图中找到所有对最短路径。 该…

Java多线程系列--“基础篇”09之 interrupt()和线程终止方式

2019独角兽企业重金招聘Python工程师标准>>> Java多线程系列--“基础篇”09之 interrupt()和线程终止方式 概要 本章&#xff0c;会对线程的interrupt()中断和终止方式进行介绍。涉及到的内容包括&#xff1a;1. interrupt()说明2. 终止线程的方式 2.1 终止处于“阻…

mac活动监视器_什么是活动监视器?

mac活动监视器活动监控 (Activity Monitor) Apple OS X provides the services of which one of them is Activity Monitor. Activity Monitor is used to monitor the activities of computer like active processes, processor load, applications that are running, and the…

concurrent包下的Exchanger练习

Exchanger可以在两个线程之间交换数据&#xff0c;只能是2个线程&#xff0c;他不支持更多的线程之间互换数据。 当线程A调用Exchange对象的exchange()方法后&#xff0c;他会陷入阻塞状态&#xff0c;直到线程B也调用了exchange()方法&#xff0c;然后以线程安全的方式交换数据…

CChelper彩虹SDK可视远程客服解决方案

本文讲的是 : CChelper彩虹SDK可视远程客服解决方案 , 在智能生态产业链中&#xff0c;智能硬件终端是把握消费者的直接环节&#xff0c;随着物联网时代迈向成熟&#xff0c;智能家居领域的硬件逐渐成为智能硬件终端的主角。目前的市场环境下&#xff0c;智能家居领域的自身硬…

php 单例模式有什么缺点_PHP的完整形式是什么?

php 单例模式有什么缺点PHP&#xff1a;超文本预处理器 (PHP: Hypertext Preprocessor ) PHP is an abbreviation of Hypertext Preprocessor, earlier called Personal Home Page. PHP is extensively used HTML-embedded, open-source server-side scripting language create…

最小跳数

Description: 描述&#xff1a; This problem is a standard interview problem which has been featured in interview rounds of Adobe, Amazon, Oyo rooms etc. 此问题是标准的采访问题&#xff0c;已在Adobe&#xff0c;Amazon&#xff0c;Oyo房间等的采访回合中出现。 P…

BE的完整形式是什么?

工学学士 (BE: Bachelor of Engineering) BE is an abbreviation of Bachelor of Engineering. It is a bachelors degree program for under graduation in engineering and the duration of this course is 4 years. It is provided in many countries like India, Canada, S…

史上最详细Windows版本搭建安装React Native环境配置

说在前面的话: 感谢同事金晓冰倾情奉献本环境搭建教程 之前我们已经讲解了React Native的OS X系统的环境搭建以及配置&#xff0c;鉴于各大群里有很多人反应在Windows环境搭建出现各种问题&#xff0c;今天就特意更新一贴来说明。关于os x环境搭建以及react native入门学习资料…

Web浏览器端通过https 使用mqtt通讯

做的产品简介 这次需要做一个web端的上课平台&#xff0c;有音视频通讯&#xff0c;有白板(画板)功能&#xff0c;有文字通讯等。技术点 音视频通讯需要走Webrtc需要跟ios, android, windows, mac 客户端互联互通一般通讯通过mqtt协议MQTT简介 MQTT&#xff08;Message Queuing…

vga显示模式_VGA的完整形式是什么?

vga显示模式VGA&#xff1a;视频图形阵列 (VGA: Video Graphics Array) VGA is an abbreviation of "Video Graphics Array". VGA是“视频图形阵列”的缩写 。 It is a three-row 15-pin DE-15 connector display hardware developed by IBM in 1987. It was first …

【iCore4 双核心板_FPGA】例程十一:FSMC总线通信实验——独立地址模式

实验原理&#xff1a; STM32F767上自带FMC控制器&#xff0c;本实验将通过FMC总线的地址独立模式实现STM32与FPGA 之间通信&#xff0c;FPGA内部建立RAM块,FPGA桥接STM32和RAM块&#xff0c;本实验通过FSMC总线从STM32向 RAM块中写入数据&#xff0c;然后读取RAM出来的数据进行…

http 412 precondition failed

2019独角兽企业重金招聘Python工程师标准>>> 今天在谷歌浏览器上刷新页面的时候&#xff0c;出现了 如下失败信息&#xff1a; HTTP 412 (Precondition Failed) 想想当时的动作是在发送ajax请求失败之后&#xff0c;再刷新&#xff0c;就会出现上面的失败问题。百度…