Codeforces Round #578 (Div. 2) B、C

C题

C. Round Corridor
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by nn sectors, and the outer area is equally divided by mm sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o’clock position.
在这里插入图片描述
The inner area’s sectors are denoted as (1,1),(1,2),…,(1,n)(1,1),(1,2),…,(1,n) in clockwise direction. The outer area’s sectors are denoted as (2,1),(2,2),…,(2,m)(2,1),(2,2),…,(2,m) in the same manner. For a clear understanding, see the example image above.

Amugae wants to know if he can move from one sector to another sector. He has qq questions.

For each question, check if he can move between two given sectors.

Input
The first line contains three integers nn, mm and qq (1≤n,m≤10181≤n,m≤1018, 1≤q≤1041≤q≤104) — the number of sectors in the inner area, the number of sectors in the outer area and the number of questions.

Each of the next qq lines contains four integers sxsx, sysy, exex, eyey (1≤sx,ex≤21≤sx,ex≤2; if sx=1sx=1, then 1≤sy≤n1≤sy≤n, otherwise 1≤sy≤m1≤sy≤m; constraints on eyey are similar). Amague wants to know if it is possible to move from sector (sx,sy)(sx,sy) to sector (ex,ey)(ex,ey).

Output
For each question, print “YES” if Amugae can move from (sx,sy)(sx,sy) to (ex,ey)(ex,ey), and “NO” otherwise.

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

Example
inputCopy
4 6 3
1 1 2 3
2 6 1 2
2 6 2 4
outputCopy
YES
NO
YES
Note
Example is shown on the picture in the statement.

题意:有两个圈1和2,1分成n块,2分成m块,各个圈的每个块之间都有一堵墙分隔。给你两个区间,问能否从区间(sx,sy)走到(ex,ey)。
思路:当两个圈的墙重合时(比如图中圈1的2和3之间的墙和圈2的3和4之间的墙),无法走到。
**一共有gcd(n,m)的墙重合,也就是说把区间分成了n和m的最大公因数块。**看给的两个区间在不在同一个块内,输出YES或NO

/**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    ll r;
    if(a<b)
        swap(a,b);
    while(a%b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return b;
}
int main()
{
    ll n,m,k,a,b,c,d;
    int q;
    ll ans[3];
    cin>>n>>m>>q;
    k=gcd(n,m);
    ans[1]=n/k;
    ans[2]=m/k;
    while(q--)
    {
        cin>>a>>b>>c>>d;
        if((b-1)/ans[a]==(d-1)/ans[c])
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

B题
B. Block Adventure
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Gildong is playing a video game called Block Adventure. In Block Adventure, there are nn columns of blocks in a row, and the columns are numbered from 11 to nn. All blocks have equal heights. The height of the ii-th column is represented as hihi, which is the number of blocks stacked in the ii-th column.

Gildong plays the game as a character that can stand only on the top of the columns. At the beginning, the character is standing on the top of the 11-st column. The goal of the game is to move the character to the top of the nn-th column.

The character also has a bag that can hold infinitely many blocks. When the character is on the top of the ii-th column, Gildong can take one of the following three actions as many times as he wants:

if there is at least one block on the column, remove one block from the top of the ii-th column and put it in the bag;
if there is at least one block in the bag, take one block out of the bag and place it on the top of the ii-th column;
if i<ni<n and |hi−hi+1|≤k|hi−hi+1|≤k, move the character to the top of the i+1i+1-st column. kk is a non-negative integer given at the beginning of the game. Note that it is only possible to move to the next column.
In actions of the first two types the character remains in the ii-th column, and the value hihi changes.

The character initially has mm blocks in the bag. Gildong wants to know if it is possible to win the game. Help Gildong find the answer to his question.

Input
Each test contains one or more test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000). Description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk (1≤n≤1001≤n≤100, 0≤m≤1060≤m≤106, 0≤k≤1060≤k≤106) — the number of columns in the game, the number of blocks in the character’s bag at the beginning, and the non-negative integer kk described in the statement.

The second line of each test case contains nn integers. The ii-th integer is hihi (0≤hi≤1060≤hi≤106), the initial height of the ii-th column.

Output
For each test case, print “YES” if it is possible to win the game. Otherwise, print “NO”.

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

Example
inputCopy
5
3 0 1
4 3 5
3 1 2
1 4 7
4 10 0
10 20 10 20
2 5 5
0 11
1 9 9
99
outputCopy
YES
NO
YES
NO
YES
Note
In the first case, Gildong can take one block from the 11-st column, move to the 22-nd column, put the block on the 22-nd column, then move to the 33-rd column.

In the second case, Gildong has to put the block in his bag on the 11-st column to get to the 22-nd column. But it is impossible to get to the 33-rd column because |h2−h3|=3>k|h2−h3|=3>k and there is no way to decrease the gap.

In the fifth case, the character is already on the nn-th column from the start so the game is won instantly.

当时读题读不懂qaq,

题意:给你n个柱子,每个柱子高相同;给你一个有m个积木的背包,背包可以无限装积木;给你数k,从柱子i到柱子i+1,要满足 |hi−hi+1|≤k|hi−hi+1|≤k。下一行n个数,表示第i个柱子上有ai个积木,(此时柱子高度等于柱子高度+积木高度)

思路:在从柱子i可以到柱子i+1的前提下尽可能从i拿走最多的积木,(以备后面需要大量积木)。如果从i不能到i+1,看背包里的积木数量能否允许从i到i+1。

/**/
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e5+5;
int main()
{
    int i,n,t,k,T;
    long long m;
    int a[110];
    cin>>T;
    for(t=1; t<=T; t++)
    {
        cin>>n>>m>>k;
        for(i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        if(n==1)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            for(i=2; i<=n; i++)
            {
                if(a[i]>a[i-1])
                {
                    if(a[i]-a[i-1]>k)
                    {
                        if(a[i]-a[i-1]-k<=m)
                        {
                            m-=(a[i]-k-a[i-1]);
                        }
                        else
                            break;
                    }
                    else
                    {
                        if(a[i]-k>=0)
                            m+=(a[i-1]-a[i]+k);
                        else
                        {
                            m+=a[i-1];
                        }
                    }
                }
                else if(a[i]<=a[i-1])
                {
                    if(a[i]-k>=0)
                        m+=(a[i-1]-a[i]+k);
                    else
                    {
                        m+=a[i-1];
                    }
                }
            }
            if(i<=n)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
        }
 
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值