Ural State University Internal Contest October'2000 Junior Session

时间:2021-09-09 14:37:31

POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~

Rope
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7410   Accepted: 2603

Description

Plotters have barberically hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they...it is awful... have roped off the nails, so that the shape felt upset (the rope was very thin). They've done it as it is shown in the figure. 
Ural State University Internal Contest October'2000 Junior Session 
Your task is to find out a length of the rope.

Input

There two numbers in the first line of the standard input: N — a number of nails (1 <= N <= 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn't exceed 100. The nails are described in a clockwise order starting from an arbitrary nail. Heads of different nails don't adjoin.

Output

The standard output should contain in its only line a real number with two digits precision (after a decimal point) — a length of the rope.

Sample Input

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

Sample Output

14.28

Source

题意:逆时针给定N个圆的圆心坐标,和半径,求外面的绳子的总长度。
猜测了一下,弧的周长,恰好是一个圆周。
有大佬用凸包,我不怎么会计算几何~~~
#include <bits/stdc++.h>

using namespace std;

#define PI acos(-1)

const int maxn = ;

struct Node {
double x,y;
}nodes[maxn]; double dist (int i,int j) {
double tx = nodes[i].x - nodes[j].x;
double ty = nodes[i].y - nodes[j].y;
return sqrt(tx*tx+ty*ty);
} int main()
{
int n;
double r;
scanf("%d%lf",&n,&r); for(int i = ; i < n; i++) {
scanf("%lf%lf",&nodes[i].x,&nodes[i].y);
} double ans = ; for(int i = ; i < n; i++) {
ans+= dist(i,(i+)%n);
} ans+= PI**r;
printf("%.2f\n",ans); return ;
}
Sacrament of the sum
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2508   Accepted: 1115

Description

— The Brother of mine, the Head of Monastic Order wants to know tomorrow about the results long-term researches. He wants to see neither more nor less than the Summering Machine! Even moreover, he wants our Machine — only a machine — to demonstrate its comprehension of the Sacrament of the Sum as deeply as it is possible. He wants our Machine to find two numbers that give the sum equal to the Sacred Number 10 000. 
— Tsh-sh-sh! This is madness that borders on blasphemy! How can the Machine calculate the Sacred Number? Twenty seven years we work on it, but we've could teach it to tell if the sum of two introduced numbers greater or lower than 10 000. Can an ordinary mortal find two numbers that there sum will be equal to 10 000? 
— But we'll have to do it with the help of our Machine, even if it is not capable. Otherwise we'll have... let's say, big problems, if it is possible to call boiling oil like this. However, I have an idea. Do you remember, last week we've entered two numbers -7 and 13 into the Machine, and it answered that their sum is lower than 10 000. I don't know how to check this, but nothing's left for us than to believe to the fruit of our work. Let's enter now a greater number than -7 and start up the Machine again. We'll do like this again and again until we find a number that being added to 13 will give us 10 000. The only thing we are to do is to prepare an ascending list of numbers. 
— I don't believe in this... Let's start with the sum that is obviously greater than the Sacred Number and we'll decrease one of the summand. So we have more chances to avoid boilin... big problems.

Haven't come to an agreement, the Brothers went away to their cells. By next day everyone of them has prepared a list of numbers that, to his opinion, could save them... Can both of the lists save them together? 
Your program should decide, if it is possible to choose from two lists of integers such two numbers that their sum would be equal to 10 000.

Input

You are given both of these lists one by one. Format of each of these lists is as follows: in the first line of the list the quantity of numbers Ni of the i-th list is written. Further there is an i-th list of numbers each number in its line (Ni lines).The following conditions are satisfied: 1 <= Ni <= 50 000, each element of the lists lays in the range from -32768 to 32767. The first list is ascending and the second one is descending.

Output

You should write "YES" to the standard output if it is possible to choose from the two lists of integers such two numbers that their sum would be equal to 10 000. Otherwise you should write "NO".

Sample Input

4
-175
19
19
10424
3
8951
-424
-788

Sample Output

YES

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed. 

Source

题意:给定两组数,挑出两个数字和为100000,中途相遇法。
#include <bits/stdc++.h>

using namespace std;

int main()
{
int n,m;
scanf("%d",&n);
set<int> s; for(int i = ; i < n; i++) {
int x;
scanf("%d",&x);
s.insert(x);
} scanf("%d",&m); bool flag = false;
for(int i = ; i < m; i++) {
int y;
scanf("%d",&y);
y = - y;
if(s.count(y)) flag = true; } if(flag)
puts("YES");
else puts("NO"); return ;
}
Genealogical tree
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6171   Accepted: 4073   Special Judge

Description

The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. They gather together in different groups, so that a Martian can have one parent as well as ten. Nobody will be surprised by a hundred of children. Martians have got used to this and their style of life seems to them natural. 
And in the Planetary Council the confusing genealogical system leads to some embarrassment. There meet the worthiest of Martians, and therefore in order to offend nobody in all of the discussions it is used first to give the floor to the old Martians, than to the younger ones and only than to the most young childless assessors. However, the maintenance of this order really is not a trivial task. Not always Martian knows all of his parents (and there's nothing to tell about his grandparents!). But if by a mistake first speak a grandson and only than his young appearing great-grandfather, this is a real scandal. 
Your task is to write a program, which would define once and for all, an order that would guarantee that every member of the Council takes the floor earlier than each of his descendants.

Input

The first line of the standard input contains an only number N, 1 <= N <= 100 — a number of members of the Martian Planetary Council. According to the centuries-old tradition members of the Council are enumerated with the natural numbers from 1 up to N. Further, there are exactly N lines, moreover, the I-th line contains a list of I-th member's children. The list of children is a sequence of serial numbers of children in a arbitrary order separated by spaces. The list of children may be empty. The list (even if it is empty) ends with 0.

Output

The standard output should contain in its only line a sequence of speakers' numbers, separated by spaces. If several sequences satisfy the conditions of the problem, you are to write to the standard output any of them. At least one such sequence always exists.

Sample Input

5
0
4 5 1 0
1 0
5 3 0
3 0

Sample Output

2 4 5 3 1

Source

题意:拓扑排序
#include <bits/stdc++.h>

using namespace std;

const int maxn = ;
int c[maxn];
int topo[maxn],t;
bool G[maxn][maxn];
int n;
bool dfs(int u) {
c[u] = -;
for(int v = ; v < n; v++) if(G[u][v]) {
if(c[v]<) return false;
else if(!c[v]&&!dfs(v)) return false;
}
c[u] = ;
topo[--t] = u;
return true;
} bool toposort() {
t = n;
memset(c,,sizeof(c));
for(int u = ; u < n; u++) if(!c[u])
if(!dfs(u)) return false;
return true;
} int main()
{
scanf("%d",&n);
for(int i = ; i < n; i++) {
int x;
while() {
scanf("%d",&x);
if(x==) break;
x--;
G[i][x] = ;
}
} toposort();
for(int i = ; i < n; i++) printf("%d ",topo[i]+);
puts(""); return ;
}
Buttons
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3892   Accepted: 1082

Description

As you surely already know, Yekaterinburg has gotten its right to hold The Summer Olympic Games of the 2032. It is planned that it will be allowed to Russia as a country-organizer to emend a program of the games a bit. So, in order to improve the command result it has been decided to replace the competition in gymnastics by the competition in the new game "Buttons". 
The rules of the game are very simple. There's a small heap of K buttons before two players. The players in turns take buttons from the heap, moreover, at a time one can take a number of buttons from 1 up to L. The one who takes the last button is the winner. 
The rules of the Olympic Games will be a bit harder then usual. The one, who is to make a first step according to a lot, has an opportunity to fix a number K with the following restriction to it: 3 <= K <= 100 000 000 (that is the exact number of buttons that has been prepared for the Olympic tournament). The player who is to make the second step fixes a number L that satisfies the following conditions 2 <= L < K. 
A very crucial task is given to your team: you are to write a program that should help the second player to make his choice. In other words, given a number K your program is to find a number L that guaranties a victory to the second player with a proper game of both sides. 
So, for instance, there are only three buttons in the heap, the choice L = 2 provides for the victory of the second player. Really, if the first player takes only one button at his turn, the second one wins, taking the two last buttons. On the contrary, if the first one takes two buttons, the second one wins, taking the last button.

Input

The standard input consists of one line, which contains an only integer number K — a number of buttons in the heap, that has fixed the first player at his turn.

Output

To the standard output you are to write the only number L — the maximal number of buttons that can be taken at a time which provides for the victory of the second player. If there are several those numbers L, you should write the least. If there are no such numbers, you are to write 0 to the standard output.

Sample Input

3

Sample Output

2

Source

题意:两个人博弈,第一个人先手,他决定一堆石子有多少个,你后手,你决定每次最多拿多少个,谁最后不能拿谁输。多组L,求最小的那个。
分析:巴什博奕 n%(m+1) + s
#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
scanf("%d",&n);
for(int m = ; m < n; m++) {
if(n%(m+)==)
{
printf("%d\n",m);
break;
}
} return ;
}
Permutations
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3281   Accepted: 1780

Description

We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows: 
Ural State University Internal Contest October'2000 Junior Session 
This record defines a permutation P as follows: P(1) = 4, P(2) = 1, P(3) = 5, etc. 
What is the value of the expression P(P(1))? It’s clear, that P(P(1)) = P(4) = 2. And P(P(3)) = P(5) = 3. One can easily see that if P(n) is a permutation then P(P(n)) is a permutation as well. In our example (believe us) 
Ural State University Internal Contest October'2000 Junior Session 
It is natural to denote this permutation by P2(n) = P(P(n)). In a general form the defenition is as follows: P(n) = P1(n), Pk(n) = P(Pk-1(n)). Among the permutations there is a very important one — that moves nothing: 
Ural State University Internal Contest October'2000 Junior Session 
It is clear that for every k the following relation is satisfied: (EN)k = EN. The following less trivial statement is correct (we won't prove it here, you may prove it yourself incidentally): Let P(n) be some permutation of an N elements set. Then there exists a natural number k, that Pk = EN. The least natural k such that Pk = EN is called an order of the permutation P. 
The problem that your program should solve is formulated now in a very simple manner: "Given a permutation find its order."

Input

In the first line of the standard input an only natural number N (1 <= N <= 1000) is contained, that is a number of elements in the set that is rearranged by this permutation. In the second line there are N natural numbers of the range from 1 up to N, separated by a space, that define a permutation — the numbers P(1), P(2),…, P(N).

Output

You should write an only natural number to the standard output, that is an order of the permutation. You may consider that an answer shouldn't exceed 109.

Sample Input

5
4 1 5 2 3

Sample Output

6

Source

题意:置换群,看题意把自己吓蒙了,求最少置换几次变成有序。
分析:每个元素置换几次的最小公倍数(lcm)
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; const int maxn = ;
int a[maxn]; int gcd(int a,int b) {
return b == ? a : gcd(b,a%b);
} int lcm(int a,int b) {
return a/gcd(a,b)*b;
} int main()
{
int n;
scanf("%d",&n); for(int i = ; i <= n; i++) scanf("%d",&a[i]); vector<int> v;
for(int i = ; i <= n; i++) { int cnt = ;
int pos = i;
while(true) {
if(a[pos]==i) break;
pos = a[pos];
cnt++;
}
v.push_back(cnt);
} int ans = ;
for(int i = ; i < (int)v.size(); i++)
ans = lcm(ans,v[i]);
cout<<ans<<endl; return ;
}
Democracy in danger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3442   Accepted: 2553

Description

In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots of them). One of the local parties, aspiring to come to power as lawfully as possible, got its way in putting into effect some reform of the election system. The main argument was that the population of the island recently had increased and it was to longer easy to hold general meetings. 
The essence of the reform is as follows. From the moment of its coming into effect all the citizens were divided into K (may be not equal) groups. Votes on every question were to be held then in each group, moreover, the group was said to vote "for" if more than half of the group had voted "for", otherwise it was said to vote "against". After the voting in each group a number of group that had voted "for" and "against" was calculated. The answer to the question was positive if the number of groups that had voted "for" was greater than the half of the general number of groups. 
At first the inhabitants of the island accepted this system with pleasure. But when the first delights dispersed, some negative properties became obvious. It appeared that supporters of the party, that had introduced this system, could influence upon formation of groups of voters. Due to this they had an opportunity to put into effect some decisions without a majority of voters "for" it. 
Let's consider three groups of voters, containing 5, 5 and 7 persons, respectively. Then it is enough for the party to have only three supporters in each of the first two groups. So it would be able to put into effect a decision with the help of only six votes "for" instead of nine, that would .be necessary in the case of general votes. 
You are to write a program, which would determine according to the given partition of the electors the minimal number of supporters of the party, sufficient for putting into effect of any decision, with some distribution of those supporters among the groups.

Input

The input of this problem contains two lines. In the first line an only natural number K <= 101 — a quantity of groups — is written. In the second line there are written K natural numbers, separated with a space. Those numbers define a number of voters in each group. In order to simplify the notion of "the majority of votes" we'll say that the number of groups also as the number of voters in each group is odd. You may also consider, that the population of the island does not exceeds 10001 persons.

Output

You should write an only natural number — a minimal quantity of supporters of the party, that can put into effect any decision.

Sample Input

3
5 7 5

Sample Output

6

Source

题意:全都是奇数,投票,求最少需要多少票。
#include <bits/stdc++.h>

using namespace std;

const int maxn = ;
int a[maxn]; int main()
{
int k;
scanf("%d",&k); for(int i = ; i <= k; i++) scanf("%d",&a[i]);
sort(a+,a++k); int ans = ;
for(int i = ; i <= (k+)/; i++)
ans+=(a[i]+)/;
printf("%d\n",ans); return ;
}
Questions and answers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11511   Accepted: 6087

Description

The database of the Pentagon contains a top-secret information. We don't know what the information is — you know, it's top-secret, — but we know the format of its representation. It is extremely simple. We don't know why, but all the data is coded by the natural numbers from 1 up to 5000. The size of the main base (we'll denote it be N) is rather big — it may contain up to 100 000 those numbers. The database is to process quickly every query. The most often query is: "Which element is i-th by its value?"— with i being a natural number in a range from 1 to N.

Your program is to play a role of a controller of the database. In the other words, it should be able to process quickly queries like this.

Input

The standard input of the problem consists of two parts. At first, a database is written, and then there's a sequence of queries. The format of database is very simple: in the first line there's a number N, in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K (1 <= K <= 100) is written, and in the next K lines there are queries one in each line. The query "Which element is i-th by its value?" is coded by the number i. A database is separated from a sequence of queries by the string of three symbols "#".

Output

The output should consist of K lines. In each line there should be an answer to the corresponding query. The answer to the query "i" is an element from the database, which is i-th by its value (in the order from the least up to the greatest element).

Sample Input

5
7
121
123
7
121
###
4
3
3
2
5

Sample Output

121
121
7
123

Source

题意:给N个数,排序好,问第几个是多少。
#include <bits/stdc++.h>

using namespace std;

const int maxn = ;
int a[maxn]; int main()
{
int n,k;
scanf("%d",&n); for(int i = ; i<=n; i++) {
scanf("%d",&a[i]);
} sort(a+,a+n+); char st[];
scanf("%s",st);
scanf("%d",&k); for(int i = ; i < k; i++) {
int x;
scanf("%d",&x);
printf("%d\n",a[x]);
} return ;
}