Codeforeces Good Bye 2017 A-C

头实在是有点痛,做了两个就坚持不住了,躺了30分钟,脑袋里浑浑噩噩,什么都没有一片空白, 浑身发热。  这个夜晚睡得最难受的一晚了。


A

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.


【题解】

奇数+元音

【代码实现】

int main()
{
    string str;
    cin>>str;
    int ans=0;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        if(str[i]=='a'||str[i]=='e'||str[i]=='o'||str[i]=='u'||str[i]=='i')
        {
            ans++;
        }
        else if(str[i]>='0'&&str[i]<='9')
        {
            if( (str[i]-'0') %2==1)
            {
                    ans++;
            }

        }
    }
    cout<<ans<<endl;
    return 0;
}

123

B

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. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its 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.


【题解】

暴力模拟把, 直接。   4!=24种  最大24种  24种排列  模拟看看这个序列能不能到达


【代码实现】

#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT std::ios::sync_with_stdio(false)
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=50005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}
int a[55][55];
// 1上 2 下 3 左 4 右
int s1,s2,e1,e2;
int ans;
int n,m;

string abc;
int main()
{

    mem(a,0);
    cin>>n>>m;
    string str;
    ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>str;
        for(int j=0;j<str.length();j++)
        {
            if(str[j]=='.')
                a[i][j]=1;
            else if(str[j]=='#')
                a[i][j]=2;
            else if(str[j]=='S')
            {
                s1=i,s2=j;
                //a[i][j]=1;
            }
            else if(str[j]=='E')
            {
                //a[i][j]=1;
                e1=i;e2=j;
            }
        }
    }
    //cout<<s1<<" "<<s2<<" "<<e1<<" "<<e2<<endl;
    cin>>abc;
    for(int x=1;x<=4;x++)
    {
        for(int y=1;y<=4;y++)
        {
            for(int z=1;z<=4;z++)
            {
                for(int d=1;d<=4;d++)
                {
                    if(x!=y&&x!=z&&x!=d&&y!=z&&y!=d&&z!=d)
                    {
                       // cout<<x<<y<<z<<d<<endl;
                        int i,j,c;
                        for(i=s1,j=s2,c=0;c<abc.length();c++)
                        {
                            if(abc[c]=='0')
                            {
                                if(x==1)//shang
                                    i-=1;
                                else if(x==2)//xia
                                    i+=1;
                                else if(x==3)//zuo
                                    j-=1;
                                else if(x==4)//you
                                    j+=1;
                            }
                            else if(abc[c]=='1')
                            {
                                if(y==1)
                                    i-=1;
                                else if(y==2)
                                    i+=1;
                                else if(y==3)
                                    j-=1;
                                else if(y==4)
                                    j+=1;
                            }
                            else if(abc[c]=='2')
                            {
                                if(z==1)
                                    i-=1;
                                else if(z==2)
                                    i+=1;
                                else if(z==3)
                                    j-=1;
                                else if(z==4)
                                    j+=1;
                            }
                            else if(abc[c]=='3')
                            {
                                if(d==1)
                                    i-=1;
                                else if(d==2)
                                    i+=1;
                                else if(d==3)
                                    j-=1;
                                else if(d==4)
                                    j+=1;
                            }
                            if(a[i][j]==2)
                                break;
                            if(i<0||i>=n||j<0||j>=m)
                                break;


                                if(i==e1&&j==e2)
                                {
                                   // cout<<x<<" "<<y<<" "<<z<<" "<<d<<endl;
                                    ans++;
                                    break;
                                }


                        }
                    }
                }
            }
        }
    }

    cout<<ans<<endl;
    return 0;
}


C

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.


【题解】

求每一个的圆的y坐标最大,能在碰到的基础上。

扫描每一个点之前的。 比较横坐标。

这个题卡 精度。


【代码实现】

cout 格式输出 20位   - -  ios:base 关掉cout和cin的绑定提高速度。  设置输出格式

#include <bits/stdc++.h>

#include <iostream>
#include <string.h>
#include <stdio.h>

#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

long double y[1200];
int n;
long double x[1200];
long double r;
int main()
{
	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
	mem(x,0);
	mem(y,0);
	cin>>n>>r;
	r=r*2;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
		y[i]=r/2;
		for(int j=0;j<i;j++)
		{
			double dx=abs(x[i]-x[j]);
			if(dx<=r)
				y[i]=max(y[i],y[j]+ sqrt(r*r-dx*dx));
		}
		cout<<y[i]<<" ";
		//printf("%.9LF ",y[i]);
	}
	cout<<endl;
	return 0;
}


posted @ 2018-01-02 18:23  Sizaif  阅读(251)  评论(0编辑  收藏  举报