Codeforces Round #431 (Div. 2) A、Odds and Ends B、Tell Your World C、From Y to Y

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个数字分割成奇数组,每一组都有奇数个数,并且每一组都以奇数开始,以奇数结束。

问是否能分割成功。


思路:

首先考虑,奇数个组,每组都为奇数个数,则总数为奇数。

那么直接分成一组就行了,只要判断下首尾两个数是否为奇数就行。


代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int i;
        int data[105];
        for(i=1;i<=n;i++)
            scanf("%d",&data[i]);
        if(!(n%2)){
            printf("no\n");
            continue;
        }
        if(data[1]%2==1&&data[n]%2==1){
            printf("Yes\n");
            continue;
        }
        printf("NO\n");
        continue;
    }
    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个数,y[1-n],表示每个点的坐标值为(i,y[i]);

求是否存在两条平行线,把所有的点都包含在内,且每条线至少包含一个点。


思路:
首先前三个点至少能确定出一个正确的斜率。

代入这个斜率判断所有的点是否符合标准即可。


代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 1005;
int data[maxn];
double ang[maxn];
int n;
int solve(double a){
    int i,j;
    int flag=0;  //只有一条也是不行的
    int now =-1;
    for(i=2;i<=n;i++){
        if(data[i]-data[1]==(a*(i-1) ) )
            continue;
        if(now==-1){
            now=i;
            flag=1;
        }
        else{
            if(data[i]-data[now]==a*(i-now))
                flag=1;
            else
                flag=0;
        }
    }
    return flag;
}

int main(){

    while(scanf("%d",&n)!=EOF){
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d",&data[i]);

        double a1= 1.0*(data[2]-data[1]);
        double a2= 1.0*(data[3]-data[2]);
        double a3= 1.0*(data[3]-data[1])/2;
        if(solve(a1)||solve(a2)||solve(a3)){
            printf("Yes\n");
        }else{
            printf("No\n");
        }

    }
    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-1次之后花费值为k的字符串。


思路:

如果字符串为aaaaaa最终的代价k由1+2+3+4+5组成;

  还不够则按bcd依次加下去即可。


代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int n;
    int sum = 0;
    scanf("%d",&n);
    if(n == 0)
    {
        printf("a\n");
        return 0;
    }
    string ans = "";
    for(char i = 'a'; i <= 'z'; i++)
    {
        if(sum == n)
            break;
        for(int j = 0; j+sum <= n; ++j)
        {
            sum += j;
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值