codeforces Good Bye 2016

A. New Year and Hurry
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.

Limak’s friends organize a New Year’s Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.

How many problems can Limak solve if he wants to make it to the party?

Input
The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

Output
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

Examples
input
3 222
output
2
input
4 190
output
4
input
7 1
output
7
Note
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn’t have enough time to solve 3 problems so the answer is 2.

In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.

In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.

8点开始做第i个题要5*i分钟,走路去聚会要k分钟。。问12点前到聚会前最多还可以做几个题

import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner in=new Scanner(System.in);
        int n,time;
        n=in.nextInt();
        time=in.nextInt();
        int havetime=240-time;
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(havetime>=i*5){
                cnt++;
                havetime-=i*5;
            }else{
                break;
            }
        }
        System.out.println(cnt);
    }
}

B. New Year and North Pole
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.

Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: “North”, “South”, “West”, “East”.

Limak isn’t sure whether the description is valid. You must help him to check the following conditions:

If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.
If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.
The journey must end on the North Pole.
Check if the above conditions are satisfied and print “YES” or “NO” on a single line.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 50).

The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Output
Print “YES” if the description satisfies the three conditions, otherwise print “NO”, both without the quotes.

Examples
input
5
7500 South
10000 East
3500 North
4444 West
4000 North
output
YES
input
2
15000 South
4000 East
output
NO
input
5
20000 South
1000 North
1000000 West
9000 North
10000 North
output
YES
input
3
20000 South
10 East
20000 North
output
NO
input
2
1000 North
1000 South
output
NO
input
4
50 South
50 North
15000 South
15000 North
output
YES
Note
Drawings below show how Limak’s journey would look like in first two samples. In the second sample the answer is “NO” because he doesn’t end on the North Pole.

这里写图片描述

问走的路是否合法,最后回到北极点。。
在北极点只能往南走,南极点只能往北走。。
提示:只要不在南极北极,,往东或西不影响。。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
using namespace std;
#define pi acos(-1.0)
#define EPS 1e-6    //log(x)
#define e exp(1.0); //2.718281828
#define mod 1000000007
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
typedef long long LL;
#define debug(x) cout<<x<<endl;
#define debug2(x) cout<<x<<" ";
const int maxn=100000+10;

int main(){
    int n;
    scanf("%d",&n);
    int dis[55];
    string op[55];
    for(int i=1;i<=n;i++){
        cin>>dis[i]>>op[i];
    }


    int d=0;
    bool ok=true;
    for(int i=1;i<=n;i++){
        if(op[i]=="North"){
            if(d-dis[i]<0) ok=false;
            d=d-dis[i];
        }
        else if(op[i]=="South"){
            if(d+dis[i]>20000) ok=false;
            d=d+dis[i];
        }
        else if(op[i]=="West"){
            if(d%20000==0) ok=false;
        }
        else if(op[i]=="East"){
            if(d%20000==0) ok=false;
        }
        if(ok==false) break;
    }
    if(ok&&d==0) printf("YES\n");
    else printf("NO\n");
    return 0;
}

C. New Year and Rating
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one’s performance, his or her rating changes by some value, possibly negative or zero.

Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division di (i.e. he belonged to this division just before the start of this contest) and his rating changed by ci just after the contest. Note that negative ci denotes the loss of rating.

What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print “Infinity”. If there is no scenario matching the given information, print “Impossible”.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000).

The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak’s rating change after the i-th contest and his division during the i-th contest contest.

Output
If Limak’s current rating can be arbitrarily big, print “Infinity” (without quotes). If the situation is impossible, print “Impossible” (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak’s current rating, i.e. rating after the n contests.

Examples
input
3
-7 1
5 2
8 2
output
1907
input
2
57 1
22 2
output
Impossible
input
1
-5 1
output
Infinity
input
4
27 2
13 1
-50 1
8 2
output
1897
Note
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:

Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.
With rating 1894 Limak is in the division 2. His rating increases by 5.
Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets  + 8 and ends the year with rating 1907.
In the second sample, it’s impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.

给出一些情况,问最后的成绩最大可能。。
只有全是在div1的才可能出现无限大的情况,,出现了div2,那么一定可以确定的。。然后就是判断合不合法。
成绩能缩小范围的是在div1和div2的变化的地方。。直接维护一个最大值和一个最小值即可

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<set>
using namespace std;
#define pi acos(-1.0)
#define EPS 1e-6    //log(x)
#define e exp(1.0); //2.718281828
#define mod 1000000007
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
typedef long long LL;
#define debug(x) cout<<x<<endl;
#define debug2(x) cout<<x<<" ";
const int maxn=200000+10;
int n;
int r[maxn],d[maxn];
int main(){

    scanf("%d",&n);
    bool allone=true;
    for(int i=1;i<=n;i++){
        cin>>r[i]>>d[i];
        if(d[i]==2) allone=false;
    }
    bool have=true;
    if(allone){
        cout<<"Infinity"<<endl;
    }
    else{
        int bigmabye=20000000;
        int minmabye=-20000000;
        int changge=0;
        for(int i=1;i<=n;i++){

            if(d[i]==1&&minmabye<1900){
                minmabye=1900;
            }
            else if(d[i]==2&&bigmabye>1899){
                bigmabye=1899;
            }
            minmabye+=r[i];
            bigmabye+=r[i];
        }
        if(minmabye<=bigmabye) cout<<bigmabye<<endl;
        else cout<<"Impossible"<<endl;
    }
    return 0;
}

D. New Year and Fireworks
time limit per test2.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.

Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, …, tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it’s possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.

Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 30) — the total depth of the recursion.

The second line contains n integers t1, t2, …, tn (1 ≤ ti ≤ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding.

Output
Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.

Examples
input
4
4 2 2 3
output
39
input
6
1 1 1 1 1 3
output
85
input
1
3
output
3
Note
For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an ‘X’ character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39.

这里写图片描述
For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level.
这里写图片描述

烟花的头可以分为两个,45度角分开,问n层之后,被烟花访问过的格子的数量;
提示:n层全为一个方向,,最深n*t=150;左右两边,,300.。所以最后的烟花只会出现在300*300的范围内所以直接枚举,,head[i][j][k][d]表示第i层,位置(j,k)上方向为d的是可达的。所以沿着这个方向走t[i]步,再得到新的两个节点。。方向编号0-7依次顺时针编号向上为0.

自己随意编号乱写了一通。。。之后膜来一发,新姿势见后边。。。
import java.util.Scanner;

public class D {

    static int dirx[] = new int[10];
    static int diry[] = new int[10];

    public static void main(String[] args) {
        dirx[1] = 0;dirx[2] = 0;dirx[3] = -1;dirx[4] = 1;
        diry[1] = 1;diry[2] = -1;diry[3] = 0;diry[4] = 0;

        dirx[5] = -1;dirx[6] = 1;dirx[7] = 1;dirx[8] = -1;
        diry[5] = 1;diry[6] = -1;diry[7] = 1;diry[8] = -1;

        @SuppressWarnings("resource")
        Scanner in = new Scanner(System.in);
        int n;
        int t[] = new int[33];
        boolean head[][][][] = new boolean[33][330][330][10];
        head[1][150][150][1] = true;
        int cnt = 0;
        boolean ok[][] = new boolean[330][330];
        n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            t[i] = in.nextInt();
            for (int j = 0; j <= 300; j++) {
                for (int k = 0; k <= 300; k++) {
                    if (head[i][j][k][1] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[1];
                            yy += diry[1];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[5]][yy + diry[5]][5] = true;
                        head[i + 1][xx + dirx[7]][yy + diry[7]][7] = true;
                    }
                    if (head[i][j][k][2] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[2];
                            yy += diry[2];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[6]][yy + diry[6]][6] = true;
                        head[i + 1][xx + dirx[8]][yy + diry[8]][8] = true;
                    }
                    if (head[i][j][k][3] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[3];
                            yy += diry[3];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[5]][yy + diry[5]][5] = true;
                        head[i + 1][xx + dirx[8]][yy + diry[8]][8] = true;
                    }
                    if (head[i][j][k][4] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[4];
                            yy += diry[4];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[6]][yy + diry[6]][6] = true;
                        head[i + 1][xx + dirx[7]][yy + diry[7]][7] = true;
                    }
                    if (head[i][j][k][5] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[5];
                            yy += diry[5];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[1]][yy + diry[1]][1] = true;
                        head[i + 1][xx + dirx[3]][yy + diry[3]][3] = true;
                    }
                    if (head[i][j][k][6] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[6];
                            yy += diry[6];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[2]][yy + diry[2]][2] = true;
                        head[i + 1][xx + dirx[4]][yy + diry[4]][4] = true;
                    }
                    if (head[i][j][k][7] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[7];
                            yy += diry[7];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[1]][yy + diry[1]][1] = true;
                        head[i + 1][xx + dirx[4]][yy + diry[4]][4] = true;
                    }
                    if (head[i][j][k][8] == true) {
                        int xx = j, yy = k;
                        if (ok[xx][yy] == false)
                            cnt++;
                        ok[xx][yy] = true;
                        for (int p = 1; p < t[i]; p++) {
                            xx += dirx[8];
                            yy += diry[8];
                            if (ok[xx][yy] == false)
                                cnt++;
                            ok[xx][yy] = true;
                        }
                        head[i + 1][xx + dirx[3]][yy + diry[3]][3] = true;
                        head[i + 1][xx + dirx[2]][yy + diry[2]][2] = true;
                    }

                } // k
            } // j
        }
        System.out.println(cnt);
    }
}

学习了新的姿势写的。。。按顺序编号。。。

import java.util.Scanner;

public class test {

    static int dirx[]={0,1,1,1, 0, -1,-1,-1};
    static int diry[]={1,1,0,-1,-1,-1, 0,1 };
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean head[][][][] = new boolean[33][330][330][10];
        head[1][150][150][0] = true;
        int cnt = 0,t;
        boolean ok[][] = new boolean[330][330];
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            t = in.nextInt();
            for(int j=0;j<=300;j++){
                for(int k=0;k<=300;k++){
                    for(int d=0;d<8;d++){
                        if(head[i][j][k][d]==true){
                            //System.out.println(j+" "+k+" "+d);
                            int xx=j,yy=k;
                            for(int g=0;g<t;g++){
                                xx+=dirx[d];
                                yy+=diry[d];
                                if(ok[xx][yy]==false) cnt++;
                                ok[xx][yy]=true;
                            }
                            head[i+1][xx][yy][(d+1)&7]=true;
                            head[i+1][xx][yy][(d+7)&7]=true;
                        }
                    }
                }
            }
        }
        System.out.println(cnt);
    }
}

后边的题不会做了。。暂时写到这里以后学习了再来补充。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值