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.

問你把長度為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.pswp.cn/news/540687.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540687.shtml
英文地址,請注明出處:http://en.pswp.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…

Verizon的SDN策略:不鳴則已,一鳴驚人?

Verizon對于其網絡虛擬化計劃的進展等一直保持緘默&#xff0c;但這并不代表Verizon沒在SDN方面投入。 Verizon于2015年推出了初步的SDN遷移計劃&#xff0c;但并未就此事對外界做過多披露。與此同時&#xff0c;它影響著它的SDN虛擬化合作伙伴。如電纜方面&#xff0c;據介紹&…

寶馬奧迪工廠模式_寶馬的完整形式是什么?

寶馬奧迪工廠模式寶馬&#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…

加拿大大數據:正在升溫的大數據市場

產業發展背景 早在2011年5月加拿大廣播電視和電信委員會&#xff08;CRTC&#xff09;就發布了新的“國家寬帶計劃”&#xff0c;該計劃顯示&#xff0c;到2015年加拿大全體國民將享有5Mbps的寬帶接入速度。CRTC表示&#xff1a;“來自市場的資金及有針對性的政府撥款將繼續推動…

scala 多線程_Scala中的多線程

scala 多線程Scala多線程 (Scala Multithreading) Multithreading is the concept of using multiple threads simultaneously that allows the program to perform multiple operations simultaneously. 多線程是同時使用多個線程的概念&#xff0c;它允許程序同時執行多個操作…

split注意事項

為什么80%的碼農都做不了架構師&#xff1f;>>> 1.特殊字符 “|”&#xff0c;“*”&#xff0c;“^”&#xff0c;"."&#xff0c;“&#xff1a;”&#xff0c;使用此字符作為分割符&#xff0c;必須用\\加以轉義 2.同時存在多個特殊字符的時候&#x…

Harbor升級和數據庫遷移手冊

Harbor升級和數據庫遷移手冊當升級一個已經存在的Harbor實例到新版本時&#xff0c;需要遷移數據庫數據。參考Whats New in Harbor Database Schema查看數據庫發生了哪些變化&#xff0c;如果有的話&#xff0c;就需要進行數據庫遷移操作&#xff0c;因為遷移可能會改變數據庫模…

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;然后以線程安全的方式交換數據…

Python默認參數

Python | 默認參數 (Python | default parameters) A default parameter is a value provided in a function declaration that is automatically assigned by the compiler if the caller of the function doesnt provide a value for the parameter with the default value. …

最長公共前綴_最長的公共前綴

最長公共前綴Problem statement: 問題陳述&#xff1a; Write a function to find the longest common prefix string amongst an array of strings. 編寫函數以在字符串數組中找到最長的公共前綴字符串 。 If there is no common prefix, return an empty string "&quo…

物聯網聽起來像是一個和互聯網不同的網,萬物互聯又把網給弄丟了,正向我們撲面而來的是萬物互聯網。...

物聯網聽起來像是一個和互聯網不同的網&#xff0c;"萬物互聯"又把"網"給弄丟了&#xff0c;正向我們撲面而來的是"萬物互聯網"。轉載于:https://www.cnblogs.com/beingonline/p/7484135.html

sdram trp_TRP的完整形式是什么?

sdram trpTRP&#xff1a;電視收視點 (TRP: Television Rating Point) TRP is an abbreviation of "Television Rating Point". TRP是“電視評分點”的縮寫 。 It is a system or standard of measurement which signifies the demand and popularity of a televisi…

Controller計算值傳到jsp頁面,用session傳值

HttpSession session request.getSession(); session.setAttribute("key",value); jap 用 ${key}來接收該值 轉載于:https://www.cnblogs.com/douder/p/7484491.html