Codeforces Good Bye 2017 - (A,B,C)

A. New Year and Counting Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your friend has n cards.

You know that each card has a lowercase English letter on one side and a digit on the other.

Currently, your friend has laid out the cards on a table so only one side of each card is visible.

You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.

For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.

To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.

Input

The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.

Output

Print a single integer, the minimum number of cards you must turn over to verify your claim.

Examples
input
ee
output
2
input
z
output
0
input
0ay1
output
2
Note

In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.

In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.

In the third sample, we need to flip the second and fourth cards.


题意:卡片有正反面,卡片要求若其一面是 'a', 'e', 'i', 'o' or 'u', 则 令一面必须是'0', '2', '4', '6' or '8'.给出一串卡片的一面,让求需要检查是否符合要求的卡片数,只要检查一面是元音字母的卡片另一面是不是偶数,和检查一面是奇数的另一面是不是元音字母就行

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 100005

char ch[55];

bool ok(int i)
{
    if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='1'||ch[i]=='3'||ch[i]=='5'||ch[i]=='7'||ch[i]=='9')
        return true;
    return false;
}

int main()
{
    int i,len;

    scanf("%s",ch);
    len=strlen(ch);
    int ans=0;
    for(i=0;i<len;i++)
    {
        if(ok(i))
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}

B. New Year and Buggy Bot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob programmed a robot to navigate through a 2d maze.

The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.

There is a single robot in the maze. It's start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. It's position is denoted with the character 'E'. This position has no obstacle in it.

The robot can only move up, left, right, or down.

When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.

The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.

Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

Input

The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.

The next n lines will contain exactly m characters each, denoting the maze.

Each character of the maze will be '.', '#', 'S', or 'E'.

There will be exactly one 'S' and exactly one 'E' in the maze.

The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.

Output

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

Examples
input
5 6
.....#
S....#
.#....
.#....
...E..
333300012
output
1
input
6 6
......
......
..SE..
......
......
......
01232123212302123021
output
14
input
5 3
...
.S.
###
.E.
...
3
output
0
Note

For the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.


题意:给出迷宫和一串命令,命令是由‘1’~‘3’组成的,0~3分别对应着4个方向,问有多少种对应方案能使得根据命令序列能从起点到达终点

用了两个dfs,第一个用来枚举每一种对应关系,第二个dfs在第一个dfs没枚举出一种情况后进行判断能否到达终点

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 100005

int n,m,ans,ex,ey,sx,sy,len;
char ins[105]; //命令序列
char mp[55][55];
char go[4];    //存放枚举结果,即是当前枚举情况下0~3分别对应go[0]~go[3],go[0]~go[3]在第一个dfs中赋予不同值
char ch[4]={'u','d','l','r'};
bool vis[4]; //四个方向的使用情况

bool ok(int x,int y,int it)
{
    if(x<0||x>=n||y<0||y>=m)
        return false;
    if(mp[x][y]=='#')
        return false;
    if(x==ex&&y==ey)
        return true;
    if(it>=len)
        return false;
    else
    {
        char temp=go[ins[it]-'0']; //temp即是ins[it]代表的方向
        if(temp=='u')
        {
            x-=1;
        }else if(temp=='d')
        {
            x+=1;
        }else if(temp=='l')
        {
            y-=1;
        }else if(temp=='r')
        {
            y+=1;
        }

        return ok(x,y,it+1);
    }
}

void dfs(int step)
{
    if(step==4) //形成一种对应
    {
        //cout<<"oooooooooooooooooooooook"<<endl;
        if(ok(sx,sy,0)) //如果可以到达终点
            ans++;
        return;
    }
    int i;
    for(i=0;i<4;i++)
    {
        if(vis[i]==false)
        {
            vis[i]=true;
            go[step]=ch[i];
            dfs(step+1);
            vis[i]=false;
        }
    }
}

int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%s",mp[i]);
        for(j=0;j<m;j++)
        {
            if(mp[i][j]=='S')
            {
                sx=i; sy=j;
            }else if(mp[i][j]=='E')
            {
                ex=i; ey=j;
            }
        }
    }
    scanf("%s",ins);
    len=strlen(ins);

    ans=0;
    memset(vis,false,sizeof(vis));
    dfs(0);

    printf("%d\n",ans);
    return 0;
}

C. New Year and Curling
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Carol is currently curling.

She has n disks each with radius r on the 2D plane.

Initially she has all these disks above the line y = 10100.

She then will slide the disks towards the line y = 0 one by one in order from 1 to n.

When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it so the disk’s y coordinate continuously decreases, and x coordinate stays constant. The disk stops once it touches the line y = 0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.

Compute the y-coordinates of centers of all the disks after all disks have been pushed.

Input

The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.

The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.

Output

Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6.

Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker program will consider your answer correct if  for all coordinates.

Example
input
6 2
5 5 6 8 3 12
output
2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613
Note

The final positions of the disks will look as follows:

In particular, note the position of the last disk.


题意:给出n个半径为r的圆,起初他们都在离轴很远的地方,他们的横坐标为x[i],现在让他们保持横坐标不变,沿着直线x=x[i]往下平移,直到接触x轴或者与其他圆

相切,这里是按照给出的横坐标的顺序往下平移的,

那么对于当前往下平移的圆,只要检查在他下方的圆是不是可能会与他相切,即两者横坐标之差小于等于直径的就有可能相切,在这些有可能相切的圆里面,它一定与纵坐标大的相切,那么通过公式sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))=2*r,即可求出y1,对于没有圆可以与他相切的情况下,它直接与x轴相切。

题目烦在精度处理,容易出问题

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define M 1005

int x[M];
double y[M];

int main()
{
    int i,j,n,r;
    scanf("%d%d",&n,&r);
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);

    y[0]=r;
    printf("%.10lf",y[0]);
    for(i=1;i<n;i++)
    {
        double cnt=r;
        for(j=0;j<i;j++)
        {
            int ab=abs(x[j]-x[i]);
            if(ab<=2*r)
            {
                cnt=max(cnt,y[j]+sqrt(4*r*r-ab*ab));
            }
        }
        y[i]=cnt;
        printf(" %.20lf",y[i]);
    }

    return 0;
}
看到Petr写的JAVA:

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int r = in.nextInt();
            int[] x = new int[n];
            double[] y = new double[n];
            for (int i = 0; i < n; ++i) {
                x[i] = in.nextInt();
                double mx = r;
                for (int j = 0; j < i; ++j) {
                    int d = Math.abs(x[j] - x[i]);
                    if (d <= 2 * r) {
                        mx = Math.max(mx, y[j] + Math.sqrt(4 * r * r - d * d));
                    }
                }
                if (i > 0) out.print(" ");
                out.print(String.format("%.10f", mx));
                y[i] = mx;
            }
            out.println();
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值