Codeforces Round #406 (Div. 2)A+B(这鬼畜的英文)

A. The Monster
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
A monster is chasing after Rick and Morty on another planet. They’re so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, … and Morty screams at times d, d + c, d + 2c, d + 3c, ….

The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.

Input
The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).

The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Output
Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.

Examples
input
20 2
9 19
output
82
input
2 1
16 12
output
-1
Note
In the first sample testcase, Rick’s 5th scream and Morty’s 8th time are at time 82.

In the second sample testcase, all Rick’s screams will be at odd times and Morty’s will be at even times, so they will never scream at the same time.
题意:给出 b, b + a, b + 2a, b + 3a,d, d + c, d + 2c, d + 3c。问是否存在某一时刻二者相等,无解输出-1。
题解:怎么也想不到正解,后来交了暴力。过了、、、

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=900010;
int a,b,c,d;
int main()
{
    cin>>a>>b;
    cin>>c>>d;
    if(b==d)
    {
        return 0*printf("%d\n",b);
    }
    else
    {
        for(int i=0;i<=1000;i++)
            for(int j=0;j<=1000;j++)
        {
            if(b+i*a==d+j*c)
            {
                return 0*printf("%d\n",b+i*a);
            }
        }
    }
    return 0*printf("-1\n");
}

B. Not Afraid
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.

There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one Morty. They’re gathering in m groups. Each person can be in many groups and a group can contain an arbitrary number of members.

Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn’t considered this possibility).

Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there’s a group such that every member in that group is a traitor (they will plan and destroy the world).

Summer knows that if there’s a possibility that world ends (there’s a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there’s at least one scenario (among all 2n possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.

Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively.

The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, …, vi, k. If vi, j is negative, it means that Rick from universe number  - vi, j has joined this group and otherwise it means that Morty from universe number vi, j has joined it.

Sum of k for all groups does not exceed 104.

Output
In a single line print the answer to Summer’s question. Print “YES” if she should cancel the event and “NO” otherwise.

Examples
input
4 2
1 -3
4 -2 3 2 -3
output
YES
input
5 2
5 3 -2 1 -1 5
3 -5 2 5
output
NO
input
7 2
3 -1 6 7
7 -5 4 2 4 7 -3 4
output
YES
Note
In the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he’s a traitor, then all members of this group are traitors and so Summer should cancel the event.
题意:题意到现在不明。
题解:判断某组是否出现±x。没出现就是YES。
代码;

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=900010;
map<int,int>mp;
int a[N];
int n,m;
int main()
{
    cin>>n>>m;
    bool flag=false;
    for(int i=1;i<=m;i++)
    {
        bool flagg=false;
        int x;
        cin>>x;
        mp.clear();
        for(int j=1;j<=x;j++)
        {
            cin>>a[j];
            mp[a[j]]++;
        }
        for(int j=1;j<=x;j++)
        {
            if(mp[-a[j]]>0)
            {
               flagg=true;
               break;
            }
        }
        if(flagg==false)
        {
            flag=true;
        }
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值