A HDU 4442
Physical Examination
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5518 Accepted Submission(s): 1519
Now WANGPENG arrives at the hospital. Er….. There are so many students, and the number is increasing!
There are many examination subjects to do, and there is a queue for every subject. The queues are getting longer as time goes by. Choosing the queue to stand is always a problem. Please help WANGPENG to determine an exam sequence, so that he can finish all the physical examination subjects as early as possible.
Then n lines follow. The i-th line has a pair of integers (ai, bi) to describe the i-th queue:
1. If WANGPENG follows this queue at time 0, WANGPENG has to wait for ai seconds to finish this subject.
2. As the queue is getting longer, the waiting time will increase bi seconds every second while WANGPENG is not in the queue.
The input ends with n = 0.
For all test cases, 0<n≤100000, 0≤ai,bi<231.
5 1 2 2 3 3 4 4 5 5 6 0
1419HintIn the Sample Input, WANGPENG just follow the given order. He spends 1 second in the first queue, 5 seconds in the 2th queue, 27 seconds in the 3th queue, 169 seconds in the 4th queue, and 1217 seconds in the 5th queue. So the total time is 1419s. WANGPENG has computed all possible orders in his 120-core-parallel head, and decided that this is the optimal choice.
<span style="color:#6600cc;">#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxN=100005;
const int mod=365*24*60*60;
struct Queue
{
long long a,b;
} q[maxN];
bool cmp(Queue x,Queue y)
{
return x.a*y.b<x.b*y.a;
}
int main()
{
int n;
while(scanf("%d",&n) && n)
{
long long sum=0,d=0;
for(int i=0; i<n; i++)
{
scanf("%I64d %I64d",&q[i].a,&q[i].b);
}
sort(q,q+n,cmp);
for(int i=0; i<n; i++)
{
sum+=(q[i].a+d*q[i].b)%mod;
sum%=mod;
d+=(q[i].a+d*q[i].b)%mod;
d%=mod;
}
printf("%I64d\n",sum);
}
return 0;
}
</span>
<span style="color:#6600cc;"></span>
<span style="color:#6600cc;">D HUD 4445</span>
Crazy Tank was a famous game about ten years ago. Every child liked it. Time flies, children grow up, but the memory of happy childhood will never go.
Now you’re controlling the tank Laotu on a platform which is H meters above the ground. Laotu is so old that you can only choose a shoot angle(all the angle is available) before game start and then any adjusting is not allowed. You need to launch N cannonballs and you know that the i-th cannonball’s initial speed is Vi.
On the right side of Laotu There is an enemy tank on the ground with coordination(L1, R1) and a friendly tank with coordination(L2, R2). A cannonball is considered hitting enemy tank if it lands on the ground between [L1,R1] (two ends are included). As the same reason, it will be considered hitting friendly tank if it lands between [L2, R2]. Laotu's horizontal coordination is 0.
The goal of the game is to maximize the number of cannonballs which hit the enemy tank under the condition that no cannonball hits friendly tank.
The g equals to 9.8.
Input
There are multiple test case.
Each test case contains 3 lines.
The first line contains an integer N(0≤N≤200), indicating the number of cannonballs to be launched.
The second line contains 5 float number H(1≤H≤100000), L1, R1(0<L1<R1<100000) and L2, R2(0<L2<R2<100000). Indicating the height of the platform, the enemy tank coordinate and the friendly tank coordinate. Two tanks may overlap.
The third line contains N float number. The i-th number indicates the initial speed of i-th cannonball.
The input ends with N=0.
Output
For each test case, you should output an integer in a single line which indicates the max number of cannonballs hit the enemy tank under the condition that no cannonball hits friendly tank.
Sample Input
2
10 10 15 30 35
10.0
20.0
2
10 35 40 2 30
10.0
20.0
0
Sample Output
1
0
Hint
In the first case one of the best choices is that shoot the cannonballs parallelly to the horizontal line, then the first
cannonball lands on 14.3 and the second lands on 28.6.
In the second there is no shoot angle to make any cannonball land between [35,40] on the condition that no
cannonball lands between [2,30].
Source
2012 Asia JinHua Regional Contest
<span style="color:#6600cc;">/*********************************
author : Grant Yuan
time : 2014-08-28 17:04:14
algorithm: 枚举
source : HDU 4445
**********************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
#define g 9.8
#define pi acos(-1.0)
#define eps 1e-8
using namespace std;
int n;
double h,l1,r1,l2,r2;
double v[207];
double cals(double k,double v1)
{
double sin1=sin(k*1.0);
double cos1=cos(k*1.0);
return v1*sin1*(v1*cos1/g+sqrt(2*h/g+v1*v1*cos1*cos1/(g*g)));
}
double calsin(double s,double v1)
{
return g*s/(2*v1*v1)-h/s;
}
int main()
{
while(1){
scanf("%d",&n);
if(!n) break;
scanf("%lf%lf%lf%lf%lf",&h,&l1,&r1,&l2,&r2);
for(int i=0;i<n;i++) scanf("%lf",&v[i]);
int ans=0,res;
double kk=pi/1000;
for(double k=0;k<=pi;k+=kk)
{
res=0; bool flag=1;
for(int i=0;i<n;i++)
{
double s=cals(k,v[i]);
if(s-l2>eps&&r2-s>eps){flag=0;break;}
else if(s-l1>eps&&r1-s>eps) res++;
}
if(flag) ans=max(ans,res);
}
printf("%d\n",ans);}
return 0;
}
</span>
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2433 Accepted Submission(s): 2037
Problem Description
Wangpeng is good at drawing. Now he wants to say numbers like “521” to his girlfriend through the game draw something.
Wangpeng can’t write the digit directly. So he comes up a way that drawing several squares and the total area of squares is the number he wants to say.
Input all the square Wangpeng draws, what’s the number in the picture?
Input
There are multiple test cases.
For each case, the first line contains one integer N(1≤N≤100) indicating the number of squares.
Second line contains N integers ai(1≤ai≤100)represent the side length of each square. No squares will overlap.
Input ends with N = 0.
Output
For each case, output the total area in one line.
Sample Input
4
1 2 3 4
3
3 3 3
0
Sample Output
30
27
Source
2012 Asia JinHua Regional Contest
<span style="color:#6600cc;">#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <cctype>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <limits>
#include <fstream>
using namespace std;
#define mem(A, X) memset(A, X, sizeof A)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define sz(x) (int)((x).size())
#define rep(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define Rep(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define dbg(a) cout << a << endl;
#define fi first
#define se second
typedef long long int64;
int gcd(const int64 &a, const int64 &b) {return b == 0 ? a : gcd(b, a % b);}
int64 int64pow(int64 a, int64 b){if(b == 0) return 1;int64 t = int64pow(a, b / 2);if(b % 2) return t * t * a;return t * t;}
const int inf = 1 << 30;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int MAX_N = 200;
int arr[MAX_N];
int n, sum;
int main()
{
while (cin >> n && n) {
sum = 0;
rep(i, 0, n) {
cin >> arr[i];
sum += arr[i] * arr[i];
}
cout << sum << endl;
}
return 0;
}
</span>
<span style="color:#6600cc;"></span>
<span style="color:#6600cc;">J HDU4451</span>
<span style="color:#6600cc;">Dressing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2389 Accepted Submission(s): 1035
Problem Description
Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K different combinations of dressing.
One day he wears his pants Nike, shoes Adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can be only clothes-pants pairs or pants-shoes pairs.
Please calculate the number of different combinations of dressing under mom’s restriction.
Input
There are multiple test cases.
For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.
Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.
Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.
The first form indicates pair of x-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1≤y≤M,1≤z≤K).
Input ends with “0 0 0”.
It is guaranteed that all the pairs are different.
Output
For each case, output the answer in one line.
Sample Input
2 2 2
0
2 2 2
1
clothes 1 pants 1
2 2 2
2
clothes 1 pants 1
pants 1 shoes 1
0 0 0
Sample Output
8
6
5
Source
2012 Asia JinHua Regional Contest
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 4984 4983 4982 4981 4980
</span><pre class="cpp" name="code"><span style="color:#6600cc;">/*********************************
author : Grant Yuan
time : 2014-08-28 14:49:44
algorithm: 组合数
source : HDU 4451
**********************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;
int num1[1007],num2[1007];
int n,m,k;
char c[20],cc[20];
int main()
{
while(1){
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
scanf("%d%d%d",&n,&m,&k);
if(!n&&!m&&!k) break;
int p;int a,b;
scanf("%d",&p);
for(int i=0;i<p;i++)
{
scanf("%s%d%s%d",c,&a,cc,&b);
if(strcmp(c,"clothes")==0){
num1[b]++;
}
else num2[a]++;
}
int ans=0;
for(int i=1;i<=m;i++)ans+=(n-num1[i])*(k-num2[i]);
printf("%d\n",ans);
}
return 0;
}</span>
K HDU 4452
<span style="color:#6600cc;">K - Running Rabbits
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
HDU 4452
Description
Rabbit Tom and rabbit Jerry are running in a field. The field is an N×N grid. Tom starts from the up-left cell and Jerry starts from the down-right cell. The coordinate of the up-left cell is (1,1) and the coordinate of the down-right cell is (N,N)。A 4×4 field and some coordinates of its cells are shown below:
The rabbits can run in four directions (north, south, west and east) and they run at certain speed measured by cells per hour. The rabbits can't get outside of the field. If a rabbit can't run ahead any more, it will turn around and keep running. For example, in a 5×5 grid, if a rabbit is heading west with a speed of 3 cells per hour, and it is in the (3, 2) cell now, then one hour later it will get to cell (3,3) and keep heading east. For example again, if a rabbit is in the (1,3) cell and it is heading north by speed 2,then a hour latter it will get to (3,3). The rabbits start running at 0 o'clock. If two rabbits meet in the same cell at k o'clock sharp( k can be any positive integer ), Tom will change his direction into Jerry's direction, and Jerry also will change his direction into Tom's original direction. This direction changing is before the judging of whether they should turn around.
The rabbits will turn left every certain hours. For example, if Tom turns left every 2 hours, then he will turn left at 2 o'clock , 4 o'clock, 6 o'clock..etc. But if a rabbit is just about to turn left when two rabbit meet, he will forget to turn this time. Given the initial speed and directions of the two rabbits, you should figure out where are they after some time.
Input
There are several test cases.
For each test case:
The first line is an integer N, meaning that the field is an N×N grid( 2≤N≤20).
The second line describes the situation of Tom. It is in format "c s t"。c is a letter indicating the initial running direction of Tom, and it can be 'W','E','N' or 'S' standing for west, east, north or south. s is Tom's speed( 1≤s<N). t means that Tom should turn left every t hours( 1≤ t ≤1000).
The third line is about Jerry and it's in the same format as the second line.
The last line is an integer K meaning that you should calculate the position of Tom and Jerry at K o'clock( 1 ≤ K ≤ 200).
The input ends with N = 0.
Output
For each test case, print Tom's position at K o'clock in a line, and then print Jerry's position in another line. The position is described by cell coordinate.
Sample Input
4
E 1 1
W 1 1
2
4
E 1 1
W 2 1
5
4
E 2 2
W 3 1
5
0
Sample Output
2 2
3 3
2 1
2 4
3 1
4 1 </span><pre class="cpp" name="code"><span style="color:#6600cc;">#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <cctype>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <limits>
#include <fstream>
using namespace std;
#define mem(A, X) memset(A, X, sizeof A)
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define sz(x) (int)((x).size())
#define rep(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define Rep(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define dbg(a) cout << a << endl;
#define fi first
#define se second
typedef long long int64;
int gcd(const int64 &a, const int64 &b) {return b == 0 ? a : gcd(b, a % b);}
int64 int64pow(int64 a, int64 b){if(b == 0) return 1;int64 t = int64pow(a, b / 2);if(b % 2) return t * t * a;return t * t;}
const int inf = 1 << 30;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int MAX_N = 500005;
//0北 1西 2南 3东
struct position
{
int x, y, s, t, to;
};
position Tom, Jerry;
int n, k;
char c;
int Turn(char c)
{
if(c == 'N') return 0;
else if(c == 'W') return 1;
else if(c == 'S') return 2;
else return 3;
}
void solve(position& pos)
{
if(pos.to == 0) {
pos.x -= pos.s;
if(pos.x < 1) {
pos.x = 2 - pos.x;
pos.to = 2;
}
}
else if(pos.to == 1) {
pos.y -= pos.s;
if(pos.y < 1) {
pos.y = 2 - pos.y;
pos.to = 3;
}
}
else if(pos.to == 2) {
pos.x += pos.s;
if(pos.x > n) {
pos.x = 2 * n - pos.x;
pos.to = 0;
}
}
else {
pos.y += pos.s;
if(pos.y > n) {
pos.y = 2 * n - pos.y;
pos.to = 1;
}
}
}
int main()
{
while(cin >> n && n) {
Tom.x = Tom.y = 1;
Jerry.x = Jerry.y = n;
getchar();
scanf("%c %d%d",&c, &Tom.s, &Tom.t);
Tom.to = Turn(c);
getchar();
scanf("%c %d%d",&c, &Jerry.s, &Jerry.t);
Jerry.to = Turn(c);
cin >> k;
Rep(i, 1, k) {
solve(Tom);
solve(Jerry);
if(Tom.x == Jerry.x && Tom.y == Jerry.y) {
swap(Tom.to, Jerry.to);
continue;
}
if(i % Tom.t == 0)
Tom.to = (Tom.to + 1) % 4;
if(i % Jerry.t == 0)
Jerry.to = (Jerry.to + 1) % 4;
}
printf("%d %d\n%d %d\n",Tom.x, Tom.y, Jerry.x, Jerry.y);
}
return 0;
}
</span>