2017.10.24

来源:互联网 发布:surf算法 编辑:程序博客网 时间:2024/05/16 03:30

1.CodeForces - 764A

Comrade Dujikov is busy choosing artists for Timofey’s birthday and is recieving calls from Taymyr from Ilia-alpinist.

Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1, 2, …, z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.

Input
The only string contains three integers — n, m and z (1 ≤ n, m, z ≤ 104).

Output
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.

Example
Input
1 1 10
Output
10
Input
1 2 5
Output
2
Input
2 3 9
Output
1
Note
Taymyr is a place in the north of Russia.

In the first test the artists come each minute, as well as the calls, so we need to kill all of them.

In the second test we need to kill artists which come on the second and the fourth minutes.

In the third test — only the artist which comes on the sixth minute.

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int gcd(int a,int b){    if(b==0)    {        return a;    }    return gcd(b,a%b);}int main (){    int n,m,k;    cin>>n>>m>>k;    int aa;    aa=n*m/gcd(n,m);    printf("%d\n",k/aa);} 

2.CodeForces - 764B
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.

In this time, Timofey’s elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to n in their order. Dima performs several steps, on step i he reverses the segment of cubes from i-th to (n - i + 1)-th. He does this while i ≤ n - i + 1.

After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.

Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes.

The second line contains n integers a1, a2, …, an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.

Output
Print n integers, separated by spaces — the numbers written on the cubes in their initial order.

It can be shown that the answer is unique.

Example
Input
7
4 3 7 6 9 1 2
Output
2 3 9 6 7 1 4
Input
8
6 1 4 2 5 6 9 2
Output
2 1 6 2 5 4 9 6
Note
Consider the first sample.

At the begining row was [2, 3, 9, 6, 7, 1, 4].
After first operation row was [4, 1, 7, 6, 9, 3, 2].
After second operation row was [4, 3, 9, 6, 7, 1, 2].
After third operation row was [4, 3, 7, 6, 9, 1, 2].
At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=200000+100;int a[maxn];int main (){    int n;    cin>>n;    for(int i=1;i<=n;i++)    {        cin>>a[i];    }    for(int i=1;i<=n-i+1;i++)    {        if(i%2==1)        {            swap(a[i],a[n-i+1]);        }    }    printf("%d",a[1]);    for(int i=2;i<=n;i++)    {        printf(" %d",a[i]);    }}

HDU - 1079

Adam and Eve enter this year’s ACM International Collegiate Programming Contest. Last night, they played the Calendar Game, in celebration of this contest. This game consists of the dates from January 1, 1900 to November 4, 2001, the contest day. The game starts by randomly choosing a date from this interval. Then, the players, Adam and Eve, make moves in their turn with Adam moving first: Adam, Eve, Adam, Eve, etc. There is only one rule for moves and it is simple: from a current date, a player in his/her turn can move either to the next calendar date or the same day of the next month. When the next month does not have the same day, the player moves only to the next calendar date. For example, from December 19, 1924, you can move either to December 20, 1924, the next calendar date, or January 19, 1925, the same day of the next month. From January 31 2001, however, you can move only to February 1, 2001, because February 31, 2001 is invalid.

A player wins the game when he/she exactly reaches the date of November 4, 2001. If a player moves to a date after November 4, 2001, he/she looses the game.

Write a program that decides whether, given an initial date, Adam, the first mover, has a winning strategy.

For this game, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input. Each test case is written in a line and corresponds to an initial date. The three integers in a line, YYYY MM DD, represent the date of the DD-th day of MM-th month in the year of YYYY. Remember that initial dates are randomly chosen from the interval between January 1, 1900 and November 4, 2001.
Output
Print exactly one line for each test case. The line should contain the answer “YES” or “NO” to the question of whether Adam has a winning strategy against Eve. Since we have T test cases, your program should output totally T lines of “YES” or “NO”.
Sample Input
3
2001 11 3
2001 11 2
2001 10 3
Sample Output
YES
NO
NO

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main (){    int t;    cin>>t;    while(t--)    {        int y,m,d;        cin>>y>>m>>d;        if((m+d)%2==0||(m==9&&d==30)||(m==11&&d==30))        {            printf("YES\n");        }        else        {            printf("NO\n");        }    }}

Dropping Balls UVA - 679

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main (){    int t;    while(cin>>t&&t>=0)    {        while(t--)        {            int n,m;            cin>>n>>m;            int ans=1;            while(n--)            {                if(m%2==1)                {                    ans=ans*2;                }                else                {                    ans=ans*2+1;                }                if(m%2==0)                {                    m=m/2;                }                else                {                    m=m/2+1;                }            }            printf("%d\n",ans/2);        }    }}
原创粉丝点击