ACM: 金华赛区题目 水题…

A.Physical Examination



Problem Description
WANGPENG is a freshman. He is requested to have a physical examination when entering the university.
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.
 

Input
There are several test cases. Each test case starts with a positive integer n in a line, meaning the number of subjects(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 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 i,b i<2 31.
 

Output
For each test case, output one line with an integer: the earliest time (counted by seconds) that WANGPENG can finish all exam subjects. Since WANGPENG is always confused by years, just print 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. 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.
题意: 排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
struct node
{
  __int64 a, b;
}qu[MAX];
__int64 n;
bool cmp(node &a, node &b)
{
  return a.a*b.b <= a.b*b.a;
}
int main()
{
  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 child liked it. Time flies, children grow up, but the memory of happy childhood will never go.
ACM: <wbr>金华赛区题目 <wbr>水题多, <wbr>难题卡了

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<100000) and L2, R2(0<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].
  题意: 在高度为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 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
题意: 平方累加和.
 
解题思路: 水题.
 
代码:
#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 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
 
题意: 有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 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:
ACM: <wbr>金华赛区题目 <wbr>水题多, <wbr>难题卡了

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
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
 
题意: 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)
      {
        char temp = 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值