POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7410 | Accepted: 2603 |
Description
Your task is to find out a length of the rope.
Input
Output
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
#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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2508 | Accepted: 1115 |
Description
— 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
Output
Sample Input
4
-175
19
19
10424
3
8951
-424
-788
Sample Output
YES
Hint
Source
#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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6171 | Accepted: 4073 | Special Judge |
Description
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
Output
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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3892 | Accepted: 1082 |
Description
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
Output
Sample Input
3
Sample Output
2
Source
#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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3281 | Accepted: 1780 |
Description
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)
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:
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
Output
Sample Input
5
4 1 5 2 3
Sample Output
6
Source
#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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3442 | Accepted: 2553 |
Description
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
Output
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 ;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11511 | Accepted: 6087 |
Description
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
Output
Sample Input
5
7
121
123
7
121
###
4
3
3
2
5
Sample Output
121
121
7
123
Source
#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 ;
}