Codeforces Round #512 (Div. 2)题解

A. In Search of an Easy Problem
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard.

If at least one of these n people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.

Input
The first line contains a single integer n (1≤n≤100) — the number of people who were asked to give their opinions.

The second line contains n integers, each integer is either 0 or 1. If i-th integer is 0, then i-th person thinks that the problem is easy; if it is 1, then i-th person thinks that the problem is hard.

Output
Print one word: “EASY” if the problem is easy according to all responses, or “HARD” if there is at least one person who thinks the problem is hard.

You may print every letter in any register: “EASY”, “easy”, “EaSY” and “eAsY” all will be processed correctly.

Examples
inputCopy
3
0 0 1
outputCopy
HARD
inputCopy
1
0
outputCopy
EASY
Note
In the first example the third person says it’s a hard problem, so it should be replaced.

In the second example the problem easy for the only person, so it doesn’t have to be replaced.
思路: 直接判断输入有不有1

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
int main()
{
    ll n;
    scanf("%lld", &n);
    int f = 0;
    for (int i = 0; i < n; ++i)
    {
        int k;
        cin >> k;
        if (k == 1) f = 1;
    }
    if (f)
        cout << "HARD" <<endl;
    else
        cout << "EASY" << endl;
    return 0;
}

B. Vasya and Cornfield
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d) and (n−d,n).

An example of a cornfield with n=7 and d=2.
Vasya also knows that there are m grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (xi,yi). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).
在这里插入图片描述
Input
The first line contains two integers n and d (1≤d<n≤100).

The second line contains a single integer m (1≤m≤100) — the number of grasshoppers.

The i-th of the next m lines contains two integers xi and yi (0≤xi,yi≤n) — position of the i-th grasshopper.

Output
Print m lines. The i-th line should contain “YES” if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i-th line should contain “NO”.

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

Examples
inputCopy
7 2
4
2 4
4 1
6 3
4 5
outputCopy
YES
NO
NO
YES
inputCopy
8 7
4
4 4
2 8
8 1
6 1
outputCopy
YES
NO
YES
YES
Note
The cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2,4)) and 4 (coordinates (4,5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4,4)), 3 (coordinates (8,1)) and 4 (coordinates (6,1)) are inside the cornfield.

在这里插入图片描述
思路: 算四边的函数,然后代入点,在中间的就是

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
int main()
{
    ll d, n;
    cin >> n >> d;
 
    int m;
    cin >> m;
 
    for (int i = 0; i < m; ++i)
    {
        ll x, y;
        cin >> x >> y;
        if (y >= x - d && y <= x + d && y >= -x + d && y <= -x + 2 * n - d)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
 
    return 0;
}

C. Vasya and Golden Ticket
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently Vasya found a golden ticket — a sequence which consists of n digits a1a2…an. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.

Help Vasya! Tell him if the golden ticket he found is lucky or not.

Input
The first line contains one integer n (2≤n≤100) — the number of digits in the ticket.

The second line contains n digits a1a2…an (0≤ai≤9) — the golden ticket. Digits are printed without spaces.

Output
If the golden ticket is lucky then print “YES”, otherwise print “NO” (both case insensitive).

Examples
inputCopy
5
73452
outputCopy
YES
inputCopy
4
1248
outputCopy
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.

In the second example it is impossible to divide ticket into segments with equal sum.

思路: 求和,然后找哪个数字可以满足要求

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
int a[1001];
char b[1001];
 
int main()
{
    int n;
 
    cin >> n;
 
    cin >> b;
 
    int sum = 0;
 
    for (int i = 0; i < n; ++i)
    {
        a[i] = b[i] - '0';
        sum += a[i];
    }
 
    for (int k = 0; k <= sum; ++k)
    {
        int f = 0;
        int cnt = 0;
        int num = 0;
        for (int i = 0; i < n; ++i)
        {
            cnt += a[i];
            if (cnt == k)
            {
                cnt = 0;
                num++;
            }
            if (cnt > k) {
                f = 1; break;
            }
        }
        if (cnt == 0 && f == 0 && num >= 2)
        {
            cout << "YES" << endl;
            return 0;
        }
    }
 
    cout << "NO" << endl;
 
    return 0;
}

D. Vasya and Triangle
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vasya has got three integers n, m and k. He’d like to find three integer points (x1,y1), (x2,y2), (x3,y3), such that 0≤x1,x2,x3≤n, 0≤y1,y2,y3≤m and the area of the triangle formed by these points is equal to nmk.

Help Vasya! Find such points (if it’s possible). If there are multiple solutions, print any of them.

Input
The single line contains three integers n, m, k (1≤n,m≤109, 2≤k≤109).

Output
If there are no such points, print “NO”.

Otherwise print “YES” in the first line. The next three lines should contain integers xi,yi — coordinates of the points, one point per line. If there are multiple solutions, print any of them.

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

Examples
inputCopy
4 3 3
outputCopy
YES
1 0
2 3
4 1
inputCopy
4 4 7
outputCopy
NO
Note
In the first example area of the triangle should be equal to nmk=4. The triangle mentioned in the output is pictured below:

In the second example there is no triangle with area nmk=167.
思路: 将其转化为以原点为直角的直角三角形,然后求边长,用一下gcd限制x <= n, y <= m。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define endl '\n'
 
typedef long long ll;
 
bool solve(ll n, ll m, ll k)
{
    if (2ll * n * m % k != 0)
        return false;
    cout << "YES" << endl;
    cout << "0 0" << endl;
    ll s = n * m * 2 / k;
    ll g = __gcd(2 * n, k);
    if (g == 1)
    {
        cout << n << " 0" << endl;
        cout << "0 " << 2 * m / k << endl;
    }
    else
    {
        cout << 2 * n / (g) << " 0" << endl;
        cout << "0 " << m * g / k << endl;
    }
    return true;
}
 
int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
 
    if (!solve(n, m, k))
        cout << "NO" << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值