Codeforces Round #180 (Div. 2)——A,B,C,D

来源:互联网 发布:mac怎么充电好 编辑:程序博客网 时间:2024/06/07 00:40
A. Snow Footprints
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.

At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in thet-th block. It is known that Alice never moves outside of the road.

You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.

Input

The first line of the input contains integer n (3 ≤ n ≤ 1000).

The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).

It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.

Output

Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

不得不说,代码写的很水,不贴了。

判断是否L,R均出现:

1.如果出现,从第一个L向左走再优走再左走回到最后一个R即可。

2.如果只有R,从第一个R走到最后一个R的后一格即可。

3.如果只有L,从最后一个L的后一格走到最后一个L即可。

B. Sail
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).

  • If the wind blows to the east, the boat will move to (x + 1, y).
  • If the wind blows to the south, the boat will move to (x, y - 1).
  • If the wind blows to the west, the boat will move to (x - 1, y).
  • If the wind blows to the north, the boat will move to (x, y + 1).

Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x, y). Given the wind direction for t seconds, what is the earliest time they sail to (ex, ey)?

Input

The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105,  - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.

The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).

Output

If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).

水题。挂了很久没搞懂为什么。后来换了个写法,给过了。

思路:贪心即可。即每次只向终点靠近。在时间内 t 判断即可。

#include <cstring>#include <cstdio>#include <iostream>#include <algorithm>using namespace std;string s;int main(){    long long sx,sy,ex,ey,t;    cin>>t>>sx>>sy>>ex>>ey;    cin>>s;    for(int i=0;i<t;i++)    {        if(s[i]=='E'&&sx<ex) sx++;        if(s[i]=='W'&&sx>ex) sx--;        if(s[i]=='S'&&sy>ey) sy--;        if(s[i]=='N'&&sy<ey) sy++;        if(sx==ex&&sy==ey)        {            cout<<i+1<<endl;            return 0;        }    }    cout<<-1<<endl;    return 0;}

C. Parity Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:

  • Write parity(a) to the end of a. For example, .
  • Remove the first character of a. For example, . You cannot perform this operation if a is empty.

You can use as many operations as you want. The problem is, is it possible to turn a into b?

The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

Input

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.

Output

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

想到1是解题的关键,就简单了。a串1的个数不能小于b串中1的个数。

当a中有奇数个1时,利用奇偶校验的特性,可增加一个1再减少.偶数则只能减少。

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int main(){    string a,b;    cin>>a>>b;    int cnt1=0,cnt2=0;    for(int i=0;a[i];i++)        if(a[i]=='1') cnt1++;    for(int i=0;b[i];i++)        if(b[i]=='1') cnt2++;    if(cnt1%2){        if(cnt1!=cnt2-1&&cnt1<cnt2) {            cout<<"NO";            return 0;        }    }    else{        if(cnt1<cnt2){            cout<<"NO";            return 0;        }    }    cout<<"YES";    return 0;}

D. Fish Weight
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.

Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight?

Input

The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species.

The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob.

Note that one may have caught more than one fish for a same species.

Output

Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.

扫描一遍,看是否对于A的每一条鱼在B中都能找到大于等于其重量的鱼即可。

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int maxn=100000+5;int A[maxn],B[maxn];int main(){    int n,m,k;    cin>>n>>m>>k;    for(int i=0;i<n;i++)        scanf("%d",&A[i]);    for(int i=0;i<m;i++)        scanf("%d",&B[i]);    sort(A,A+n);    sort(B,B+m);    int j=0,i=0;    while(i<n&&j<m)    {        if(A[i]<=B[j]) i++,j++;        else j++;    }    if(i==n) cout<<"NO";    else cout<<"YES";    return 0;}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 衣服碰到了酒店的毛巾被单怎么办 防晒喷雾弄衣服上有荧光怎么办 剑网3重置版删除后有残留怎么办 在超市买到变质的水果怎么办 微信官方电话一直打不通怎么办 对方欠货款股东换了不还怎么办 闲鱼买的东西确认收货有问题怎么办 不让微信好友看到吃鸡的名字怎么办 金鹰贵宾积分卡过期了怎么办 小宝机器人一直停在联网界面怎么办 手机版的有道云笔记忘记邮箱怎么办 钡灌肠复查钡剂排空不良怎么办 两个月宝宝灌肠后不排便怎么办 一岁宝宝肠套叠灌肠后拉肚子怎么办 苹果手机自带的天气没有了怎么办? 衣服在洗衣机里忘记拿出来怎么办 苹果se手机系统占内存太大怎么办 客人把饭店老板打了民警怎么办 商场嫌品牌低端不让入驻怎么办 带着孩子坐飞机座位不在一起怎么办 公司老板跑路了员工该怎么办 超市买的衣服防盗扣忘记取了怎么办 在超市买的衣服那个扣没取怎么办啊 超市散称商品条码老记不住怎么办 app账号密码忘记了怎么办注销难 幼儿老师遇到家长比较孩子该怎么办 发的微信公众号内容重复了怎么办 招嫖诈骗微信转账被骗怎么办 朋友在深圳龙岗被传销骗了要怎么办 怀疑家里人被传销组织骗去了怎么办 怀疑家人被骗进传销了该怎么办 b本扣3分了怎么办2018 抖音里面就剩人头的视频怎么办 自学参加普通高考那小高考怎么办 如果小学生长胸只长了一个该怎么办 脸上毛多导致的毛孔粗怎么办 吃了激素药头发掉的厉害怎么办 剪发的剪子中间的螺丝扣总掉怎么办 染完头发后一段时间长新头发怎么办 睡觉头发老被老公压着怎么办 漆盖关节不自在怎么办?吃什么好