ACM: 金华赛区题目 水题…

来源:互联网 发布:java酒店管理系统程序 编辑:程序博客网 时间:2024/05/11 06:00

A.PhysicalExamination



Problem Description
WANGPENG is a freshman. He is requested to have a physicalexamination when entering the university.
Now WANGPENG arrives at the hospital. Er….. There are so manystudents, and the number is increasing!
There are many examination subjects to do, and there is a queue forevery subject. The queues are getting longer as time goes by.Choosing the queue to stand is always a problem. Please helpWANGPENG to determine an exam sequence, so that he can finish allthe physical examination subjects as early as possible.
 

Input
There are several test cases. Each test case starts with apositive integer n in a line, meaning the number ofsubjects(queues).
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 waitfor ai seconds to finish this subject.
2. As the queue is getting longer, the waiting time will increasebi seconds every second while WANGPENG is not in the queue.
The input ends with n = 0.
For all test cases,0i,bi<231.
 

Output
For each test case, output one line with an integer: theearliest time (counted by seconds) that WANGPENG can finish allexam subjects. Since WANGPENG is always confused by years, justprint the seconds mod 365×24×60×60.
 

Sample Input
5
1 2
2 3
3 4
4 5
5 6
0
 

Sample Output
1419
Hint
In the Sample Input, WANGPENG just follow the given order. Hespends 1 second in the first queue, 5 seconds in the 2th queue, 27seconds in the 3th queue, 169 seconds in the 4th queue, and 1217seconds in the 5th queue. So the total time is 1419s. WANGPENG hascomputed all possible orders in his 120-core-parallel head, anddecided that this is the optimal choice.
题意: 排n支队伍,每支队伍排队时间ai, 每支队伍会随时间增加都增长. 求最短排队时间.
 
解题思路:
       1. 设当前结果的时间time, 每次选择都有(a1, b1), (a2, b2).
          选择1队列先的耗时:time1 = (time+a1+b1*time +a2+b2*(time+a1+b1*time));
          选择2队列先的耗时:time2 = (time+a2+b2*time +a1+b1*(time+a2+b2*time));
           time1<= time2 化简得: a1*b2 <= a2*b1.
       2. 从小到大排序, 依次去一支队伍计算时间就是最小值. 最后要注意使用__int64
          or long long. 奉献了几次WA在这里.
 
代码:
#include<cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 100005
#define MOD 31536000
structnode
{
 __int64 a, b;
}qu[MAX];
__int64n;
boolcmp(node &a, node &b)
{
 return a.a*b.b <= a.b*b.a;
}
intmain()
{
 int i;
// freopen("input.txt", "r", stdin);
 while(scanf("%d", &n) !=EOF)
 {
  if(n == 0) break;
  for(i = 1; i <=n; ++i)
  {
   scanf("%I64d%I64d", &qu[i].a, &qu[i].b);
  }
  sort(qu+1, qu+n+1, cmp);
  __int64 sum = 0;
  for(i = 1; i <=n; ++i)
  {
   sum +=(qu[i].a%MOD + (qu[i].b%MOD)*(sum%MOD)%MOD )%MOD;
   sum %=MOD;
  }
  printf("%I64d\n", sum);
 }
 return 0;
}
 
 

D.Crazy Tank



Problem Description
Crazy Tank was a famous game about ten years ago. Every childliked it. Time flies, children grow up, but the memory of happychildhood will never go.
ACM: <wbr>金华赛区题目 <wbr>水题多, <wbr>难题卡了

Now you’re controlling the tank Laotu on a platform which is Hmeters above the ground. Laotu is so old that you can only choose ashoot angle(all the angle is available) before game start and thenany adjusting is not allowed. You need to launch Ncannonballs and you know that the i-th cannonball’s initial speedis Vi.
On the right side of Laotu There is an enemy tank on the groundwith coordination(L1, R1) and a friendly tank with coordination(L2,R2). A cannonball is considered hitting enemy tank if it lands onthe ground between [L1,R1] (two ends are included). As the samereason, it will be considered hitting friendly tank if it landsbetween [L2, R2]. Laotu's horizontal coordination is 0.
The goal of the game is to maximize the number of cannonballs whichhit the enemy tank under the condition that no cannonball hitsfriendly 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 thenumber of cannonballs to be launched.
The second line contains 5 float number H(1≤H≤100000), L1,R1(0<100000) and L2, R2(0<100000).Indicating the height of the platform, the enemy tank coordinateand the friendly tank coordinate. Two tanks mayoverlap.
The third line contains N float number. The i-th number indicatesthe initial speed of i-th cannonball.
The input ends with N=0.
 

Output
For each test case, you should output an integer in a singleline which indicates the max number of cannonballs hit the enemytank under the condition that no cannonball hits friendlytank.
 

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 thecannonballs parallelly to the horizontal line, then the firstcannonball lands on 14.3 and the second lands on 28.6. In thesecond there is no shoot angle to make any cannonball land between[35,40] on the condition that no cannonball lands between[2,30].
 题意: 在高度为H的位置一部坦克,你可以调整任意角度一次, 发射n发炮弹, 不可以击中队友,
问你最大可以击中敌人的次数.
 
解题思路:
       1. 简单的高中物理题. 如图: ACM: <wbr>金华赛区题目 <wbr>水题多, <wbr>难题卡了
       2. a的取值0~pi(3.1415926), 在某一个角度出现最大值, 枚举阀值eps =pi/1000.
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
#define MAX 205
const double pi = acos(-1*1.0);
int n;
double H, L1, R1, L2, R2;
double v[MAX];
int result;
inline int max(int a, int b)
{
 return a > b ? a : b;
}
inline int solve(double angle)
{
 int result = 0;
 double dist;
 for(int i = 1; i <= n; ++i)
 {
  double a = 0.5*9.8;
  double b = vi*cos(angle);
  double c = -H;
  double mid = b*b-4*a*c;
  double t =(-b+sqrt(mid))/(2*a);
  double dist =vi*sin(angle)*t;
  if( dist >= L1&& dist <= R1 )result++;
  if( dist >= L2&& dist <= R2 )return 0;
 }
 return result;
}
int main()
{
// freopen("input.txt", "r", stdin);
 while(scanf("%d", &n) !=EOF)
 {
  if(n == 0) break;
  scanf("%lf %lf%lf %lf %lf", &H, &L1,&R1, &L2,&R2);
  for(int i = 1; i<= n; ++i)
   scanf("%lf",&v[i]);
  
  result = 0;
  for(double angle = 0; angle< pi; angle += pi/1000)
  {
   result =max(result, solve(angle));
   if(result ==n) break;
  }
  printf("%d\n", result);
 }
 return 0;
}
 
 

I. Draw Something



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 thatdrawing several squares and the total area of squares is the numberhe wants to say.
Input all the square Wangpeng draws, what’s the number in thepicture?
 

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 sidelength 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
题意: 平方累加和.
 
解题思路: 水题.
 
代码:
#include<cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int n;
int side;
int main()
{
// freopen("input.txt", "r", stdin);
 while(scanf("%d", &n) !=EOF)
 {
  if(n == 0) break;
  int sum = 0;
  for(int i = 1; i<= n; ++i)
  {
   scanf("%d",&side);
   sum +=side*side;
  }
  printf("%d\n", sum);
 }
 return 0;
}
 

J. Dressing


Problem Description
Wangpeng has N clothes, M pants and K shoes so theoreticallyhe can have N×M×K different combinations of dressing.
One day he wears his pants Nike, shoes Adiwang to go to schoolhappily. When he opens the door, his mom asks him to come back andswitch the dressing. Mom thinks that pants-shoes pair isdisharmonious because Adiwang is much better than Nike. After beingasked to switch again and again Wangpeng figure out all the pairsmom thinks disharmonious. They can be only clothes-pants pairs orpants-shoes pairs.
Please calculate the number of different combinations of dressingunder mom’s restriction.
 

Input
There are multiple test cases.
For each case, the first line contains 3 integersN,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants andshoes.
Second line contains only one integer P(0≤P≤2000000) indicating thenumber of pairs which mom thinks disharmonious.
Next P lines each line will be one of the two forms“clothes x pantsy” or “pants y shoes z”.
The first form indicates pair of x-th clothes and y-th pants isdisharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-thpants 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
 
题意: 有n件衣服, m条裤子和k双鞋子.其中有衣服和裤子不搭配和裤子和衣服不搭配的组合.
求出现在剩下可以搭配的衣服,裤子和鞋子的组合数.
 
解题思路:
1. 以裤子为关键, 原来组合一共有n*m*k, 分解成∑(n*k), (m个(n*k累加)),以为一些衣服
和裤子, 裤子和鞋子不搭配的组合, 分别记录下数目clothes[i],shoes[i].
2. 因此, 最后结果 (n-colthes[1])*(k-shoes[1])+...+(n-colthes[k])*(k-shoes[k]).
 
代码:
#include<cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 1005
int n, m, k;
char str1[20], str2[20];
int a, b;
int clothes[MAX], shoes[MAX];
int main()
{
// freopen("input.txt", "r", stdin);
 while(scanf("%d %d %d", &n,&m, &k) != EOF)
 {
  if(n == 0&& m == 0&& k == 0) break;
  int num;
  int result = 0;
  scanf("%d",&num);
  memset(clothes, 0,sizeof(clothes));
  memset(shoes, 0,sizeof(shoes));
  for(int i = 1; i<= num; ++i)
  {
   scanf("%s %d%s %d", str1, &a, str2, &b);
   if(strcmp(str1, "clothes") == 0)
    clothes[b]++;
   else
    shoes[a]++;
  }
  for(int j =1; j <= m; ++j)
   result +=(n-clothes[j])*(k-shoes[j]);
  printf("%d\n", result);
 }
 return 0;
}
 

K.Running Rabbits



Problem Description
Rabbit Tom and rabbit Jerry are running in a field. The fieldis an N×N grid. Tom starts from the up-left cell and Jerry startsfrom 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×4field and some coordinates of its cells are shown below:
ACM: <wbr>金华赛区题目 <wbr>水题多, <wbr>难题卡了

The rabbits can run in four directions (north, south, west andeast) and they run at certain speed measured by cells per hour. Therabbits can't get outside of the field. If a rabbit can't run aheadany more, it will turn around and keep running. For example, in a5×5 grid, if a rabbit is heading west with a speed of 3 cells perhour, and it is in the (3, 2) cell now, then one hour later it willget to cell (3,3) and keep heading east. For example again, if arabbit is in the (1,3) cell and it is heading north by speed 2,thena hour latter it will get to (3,3). The rabbits start running at 0o'clock. If two rabbits meet in the same cell at k o'clock sharp( kcan be any positive integer ), Tom will change his direction intoJerry's direction, and Jerry also will change his direction intoTom's original direction. This direction changing is before thejudging of whether they should turn around.
The rabbits will turn left every certain hours. For example, if Tomturns left every 2 hours, then he will turn left at 2 o'clock , 4o'clock, 6 o'clock..etc. But if a rabbit is just about to turn leftwhen two rabbit meet, he will forget to turn this time. Given theinitial speed and directions of the two rabbits, you should figureout 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×Ngrid( 2≤N≤20).
The second line describes the situation of Tom. It is in format "cs 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 orsouth. s is Tom's speed( 1≤s
The third line is about Jerry and it's in the same format as thesecond line.
The last line is an integer K meaning that you should calculate theposition 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 aline, and then print Jerry's position in another line. The positionis 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
 
题意: 2只兔子在矩阵中跑, 每只兔子会有速度, 当遇到墙壁时会往相反方向跑,并且会隔一段时间,
会向左转一次, 当2只兔子想会面时, 他们会交换方向, 并且向左转的时间要重新计算,问经过
K个时间后, 他们会停留在数目位置.
 
解题思路:
1. 直接模拟即可.
 
代码:
#include<cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int n, m;
char dir1[2], dir2[2];
int t1, t2;
int v1, v2;
int x1, y1, x2, y2;
void run(char &dir, int v, int&x, int &y)
{
 if(dir == 'W') x -= v;
 else if(dir == 'E') x += v;
 else if(dir == 'S') y += v;
 else if(dir == 'N') y -= v;
 if(x > n)
 {
  x = 2*n-x;
  dir = 'W';
 }
 if(x < 1)
 {
  x = 2-x;
  dir = 'E';
 }
 if(y > n)
 {
  y = 2*n-y;
  dir = 'N';
 }
 if(y < 1)
 {
  y = 2-y;
  dir = 'S';
 }
}
char change(char dir)
{
 if(dir == 'E') return 'N';
 else if(dir == 'W') return 'S';
 else if(dir == 'S') return 'E';
 else if(dir == 'N') return 'W';
}
int main()
{
// freopen("input.txt", "r", stdin);
 while(scanf("%d", &n) !=EOF)
 {
  if(n == 0) break;
  scanf("%s %d%d", dir1, &v1, &t1);
  scanf("%s %d %d", dir2,&v2, &t2);
  x1 = y1 = 1;
  x2 = y2 = n;
  scanf("%d",&m);
  for(int i = 1; i<= m; ++i)
  {
   run(dir1[0],v1, x1, y1);
   run(dir2[0],v2, x2, y2);
   if(x1 == x2&& y1 == y2)
   {
    chartemp = dir1[0];
    dir1[0]= dir2[0];
    dir2[0]= temp;
   }
   else
   {
    if(i % t1 == 0 ) dir1[0] = change(dir1[0]);
    if(i % t2 == 0 ) dir2[0] = change(dir2[0]);
   }
  }
  printf("%d%d\n%d %d\n", y1, x1, y2, x2);
 }
 return 0;
}
 
总结: 这5题A题需要注意精度问题, 容易出错. K题模拟题也需要注意细节和方向改变.其他没什么了.
一直卡在C题, 到现在还没做出来, 思路是: 先将坐标离散化, (x,y)-> x*3,x*3-1,x*3+1.
这样重新将坐标划分. 每个障碍建筑内部标记为不可行走, 并且标记2个障碍建筑如果相邻,那么
它们的边也是不可行走, 否则可以行走, 建筑的四个顶点标记相交时不可行走. 最后,用spfa求
最短路. 设dist[x][y][dir]表示从起点到(x,y)点从方向dir到达,最少的转弯次数. 一直WA,
继续思考中.
0 0
原创粉丝点击