CROC-MBTU 2012, Elimination Round (ACM-ICPC)

A. System Administrator
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.

Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.

Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

Input

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following nlines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers tixi,yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xiyi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yipackets were lost.

It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

Output

In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).

In the second line print the state of server b in the similar format.

Sample test(s)
input
2
1 5 5
2 6 4
output
LIVE
LIVE
input
3
1 0 10
2 0 10
1 10 0
output
LIVE
DEAD
Note

Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.

Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.

统计第一类的是否大于等于第二类的,输出LIVE;否则输出 DEAD

#include <stdio.h>
#include <string.h>
int main()
{
    int a[2][2];
    memset(a,0,sizeof(a));
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int t,b,c;
        scanf("%d%d%d",&t,&b,&c);
        if(t==1)
            a[0][0]+=b,a[0][1]+=c;
        if(t==2)
            a[1][0]+=b,a[1][1]+=c;
    }
    if(a[0][0]>=a[0][1])
        printf("LIVE\n");
    else
        printf("DEAD\n");
    if(a[1][0]>=a[1][1])
        printf("LIVE\n");
    else
        printf("DEAD\n");
    return 0;
}


B. Internet Address
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:

<protocol>://<domain>.ru[/<context>]

where:

  • <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes),
  • <domain> is a non-empty string, consisting of lowercase English letters,
  • the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters.

If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context).

When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".".

Help Vasya to restore the possible address of the recorded Internet resource.

Input

The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.

It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.

Output

Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.

Sample test(s)
input
httpsunrux
output
http://sun.ru/x
input
ftphttprururu
output
ftp://http.ru/ruru
Note

In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru".


字符串处理,就是有两个地方需要注意一下,1.ru的后面什么都没有的时候那个 / 不要 2.第二部分第一个就是ru的时候忽略

#include <stdio.h>
#include <string.h>
int main()
{
    char s[1000];
    gets(s);
    int l=strlen(s);
    int tag,i;
    if(s[0]=='h')
    {
        printf("http://");
        tag=4;
    }
    else if(s[0]=='f')
    {
        printf("ftp://");
        tag=3;
    }
    for(i=tag;i<l;i++)
    {
        if(i!=tag&&s[i]=='r'&&s[i+1]=='u')
            break;
        printf("%c",s[i]);
    }
    printf(".ru");
    if(i+2!=l)
    printf("/%c",s[i+2]);
    for(int j=i+3;j<l;j++)
    {
        printf("%c",s[j]);
    }
    printf("\n");
    return 0;
}


C. Game with Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins.

Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer x (2·x + 1 ≤ n) and take a coin from each chest with numbers xxx + 1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied.

Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of chests with coins. The second line contains a sequence of space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai is the number of coins in the chest number i at the beginning of the game.

Output

Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1.

Sample test(s)
input
1
1
output
-1
input
3
1 2 3
output
3
Note

In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests.

In the second sample there is only one possible move x = 1. This move should be repeated at least 3 times to empty the third chest.


贪心,首先必须是大于2的奇数,然后从倒着贪心

#include <stdio.h>
#define max(a,b) (a>b?a:b)
int main()
{
    int n;
    int a[110];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n<=2||n%2==0)
        printf("-1\n");
    else
    {
        int step=0;
        for(int i=n;i>=1;i--)
        {
            if(2*i+1<=n)
            {
                int sb=max(a[i*2+1],a[i*2]);
                step+=sb;
                a[2*i]=a[2*i+1]=0;
                a[i]-=sb;
                a[i]=(a[i]>0?a[i]:0);
            }
        }
        step+=a[1];
        a[1]=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i])
                step--;
        }
        printf("%d\n",step);
    }
    return 0;
}


D. Restoring Table
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.

For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals:

  • the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j;
  • -1, if i = j.

Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.

Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n)the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ ni ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109bij = bji.

Output

Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.

It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.

Sample test(s)
input
1
-1
output
0 
input
3
-1 18 0
18 -1 0
0 0 -1
output
18 18 0 
input
4
-1 128 128 128
128 -1 148 160
128 148 -1 128
128 160 128 -1
output
128 180 148 160 
Note

If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.


题目意思就是这个矩阵a是由一组b得到的,a[i][i]=-1 其余的a[i][j]=a[i]&a[j]

所以逆过去求就是将一排所有的全部进行 | 的位运算,就还原了

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#define N 101
int a[N][N];
int b[N];
int main()
{
    int n;
    scanf("%d",&n);
    memset(b,0,sizeof(b));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&a[i][j]);
            if(i!=j)
            b[i]|=a[i][j];
        }
    }
    for(int i=1;i<n;i++)
        printf("%d ",b[i]);
    printf("%d\n",b[n]);
    return 0;
}


E. Mishap in Club
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.

On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.

Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.

Input

The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.

Output

Print the sought minimum number of people

Sample test(s)
input
+-+-+
output
1
input
---
output
3


模拟人的进出,求某时刻人最多的时候

#include <stdio.h>
#include <string.h>
int main()
{
    char str[400];
    gets(str);
    int l=strlen(str);
    int s=0,y=0,tag=0;
    for(int i=0;i<l;i++)
    {
        if(str[i]=='+')
        {
            if(s>0)
                s--;
            else
                tag++;
            y++;
        }
        else if(str[i]=='-')
        {
            if(y>0)
                y--;
            else
                tag++;
            s++;
        }
    }
    printf("%d\n",tag);
    return 0;
}


F. Log Stream Analysis
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got a list of program warning logs. Each record of a log stream is a string in this format:

" 2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes).

String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct time in the 24 hour format.

The described record of a log stream means that at a certain time the record has got some program warning (string "MESSAGE" contains the warning's description).

Your task is to print the first moment of time, when the number of warnings for the last n seconds was not less than m.

Input

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 10000).

The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log stream has the above described format. All records are given in the chronological order, that is, the warning records are given in the order, in which the warnings appeared in the program.

It is guaranteed that the log has at least one record. It is guaranteed that the total length of all lines of the log stream doesn't exceed5·106 (in particular, this means that the length of some line does not exceed 5·106 characters). It is guaranteed that all given dates and times are correct, and the string 'MESSAGE" in all records is non-empty.

Output

If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last n seconds got no less than m.

Sample test(s)
input
60 3
2012-03-16 16:15:25: Disk size is
2012-03-16 16:15:25: Network failute
2012-03-16 16:16:29: Cant write varlog
2012-03-16 16:16:42: Unable to start process
2012-03-16 16:16:43: Disk size is too small
2012-03-16 16:16:53: Timeout detected
output
2012-03-16 16:16:43
input
1 2
2012-03-16 23:59:59:Disk size
2012-03-17 00:00:00: Network
2012-03-17 00:00:01:Cant write varlog
output
-1
input
2 2
2012-03-16 23:59:59:Disk size is too sm
2012-03-17 00:00:00:Network failute dete
2012-03-17 00:00:01:Cant write varlogmysq
output
2012-03-17 00:00:00


模拟题,求某时与下一事件的差值大于等于n的时候,这个题主要是时间上的控制问题,每个月啊天数不同什么的,看别人代码过的,把时间入队...

给的样例,第一组还没输完,就结束了;而第二组输出用ctrl+z结束。。。哈哈。。郁闷了好久

#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#define maxn 10000010
using namespace std;
int month[13]={0,31,29,31,30,31,30,31,31,30,31,30};
queue<long long>q;
int n,m;
char s[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    while(scanf("%s",s)!=EOF)
    {
    long long time=0;
    int M=(s[5]-'0')*10+(s[6]-'0');
    int D=(s[8]-'0')*10+(s[9]-'0');
    for(int i=1;i<M;++i)
        time+=month[i];
    time+=D-1;
    time*=24*3600;
    int hh,mm,ss;
    scanf("%d:%d:%d",&hh,&mm,&ss);
    gets(s);
    time+=hh*3600+mm*60+ss;
    q.push(time);
    while(q.front()<=time-n)
    q.pop();
    if(q.size()>=m)
    {
        printf("2012-%02d-%02d %02d:%02d:%02d\n",M,D,hh,mm,ss);
        return 0;
    }
    }
    printf("-1\n");
    return 0;
}

G. Suggested Friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarpus works as a programmer in a start-up social network. His boss gave his a task to develop a mechanism for determining suggested friends. Polycarpus thought much about the task and came to the folowing conclusion.

Let's say that all friendship relationships in a social network are given as m username pairs ai, bi (ai ≠ bi). Each pair ai, bi means that users ai and bi are friends. Friendship is symmetric, that is, if ai is friends with bi, then bi is also friends with ai. User y is a suggested friend for user x, if the following conditions are met:

  1. x ≠ y;
  2. x and y aren't friends;
  3. among all network users who meet the first two conditions, user y has most of all common friends with user x. User z is a common friend of user x and user y (z ≠ x, z ≠ y), if x and z are friends, and y and z are also friends.

Your task is to help Polycarpus to implement a mechanism for determining suggested friends.

Input

The first line contains a single integer m (1 ≤ m ≤ 5000) — the number of pairs of friends in the social network. Next m lines contain pairs of names of the users who are friends with each other. The i-th line contains two space-separated names ai and bi (ai ≠ bi). The users' names are non-empty and consist of at most 20 uppercase and lowercase English letters.

It is guaranteed that each pair of friends occurs only once in the input. For example, the input can't contain xy and yx at the same time. It is guaranteed that distinct users have distinct names. It is guaranteed that each social network user has at least one friend. The last thing guarantees that each username occurs at least once in the input.

Output

In the first line print a single integer n — the number of network users. In next n lines print the number of suggested friends for each user. In the i-th line print the name of the user ci and the number of his suggested friends di after a space.

You can print information about the users in any order.

Sample test(s)
input
5
Mike Gerald
Kate Mike
Kate Tank
Gerald Tank
Gerald David
output
5
Mike 1
Gerald 1
Kate 1
Tank 1
David 2
input
4
valera vanya
valera edik
pasha valera
igor valera
output
5
valera 0
vanya 3
edik 3
pasha 3
igor 3
Note

In the first test case consider user David. Users Mike and Tank have one common friend (Gerald) with David. User Kate has no common friends with David. That's why David's suggested friends are users Mike and Tank.


图论哈.....@黄建大神  交给你了 表示不会做 也不想做

H. Queries for Number of Palindromes
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of substrings of string s[li... ri], which are palindromes.

String s[l... r] = slsl + 1... sr (1 ≤ l ≤ r ≤ |s|) is a substring of string s = s1s2... s|s|.

String t is called a palindrome, if it reads the same from left to right and from right to left. Formally, if t = t1t2... t|t| = t|t|t|t| - 1... t1.

Input

The first line contains string s (1 ≤ |s| ≤ 5000). The second line contains a single integer q (1 ≤ q ≤ 106) — the number of queries. Next q lines contain the queries. The i-th of these lines contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ |s|) — the description of the i-th query.

It is guaranteed that the given string consists only of lowercase English letters.

Output

Print q integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces.

Sample test(s)
input
caaaba
5
1 1
1 4
2 3
4 6
4 5
output
1
7
3
4
2
Note

Consider the fourth query in the first test case. String s[4... 6] = «aba». Its palindrome substrings are: «a», «b», «a», «aba».


求某段之间,能产生回文串的个数,dp,然后累加

#include <stdio.h>
#include <string.h>
#define maxn 5010
char s[maxn];
int miao[maxn][maxn],tag[maxn][maxn];
int main()
{
    scanf("%s",s);
    int l=strlen(s);
    for(int i=1;i<=l;i++)//i表示回文串的长度
        for(int j=0;j<l-i+1;j++)//j表示起始位置
        {
            miao[i][j]=0;
            if(i==1) tag[j][j]=1;
            else if(i==2) tag[j][j+i-1]=(s[j]==s[j+i-1]);
            else tag[j][j+i-1]=tag[j+1][j+i-2]&&(s[j+i-1]==s[j]);
        }
    for(int i=0;i<l;i++)
    {
        miao[i][i]=tag[i][i];
        for(int j=i+1;j<l;j++)
            miao[i][j]=miao[i][j-1]+tag[i][j];
    }
    for(int i=0;i<l;i++)
    {
        miao[i][i]=tag[i][i];
        for(int j=i-1;j>=0;j--)
            miao[j][i]+=miao[j+1][i];
    }
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        printf("%d\n",miao[x-1][y-1]);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值