2013个人赛(合)001

来源:互联网 发布:淘宝助理mac官方版 编辑:程序博客网 时间:2024/04/30 04:07

18岁生日

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14758    Accepted Submission(s): 4708

Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
Input
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。
Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。
Sample Input
11988-03-07
 
Sample Output
6574
Author
Gardon
Source
Gardon-DYGG Contest 2
Recommend
JGShining
 
C/C++:
假设每一年都是平年,则共有365*18天,我们只需要再计算这些年中经历了多少个2月29日
这样时间复杂度稍微降了一点(0 MS):
#include <iostream>using namespace std;struct Date{    int Y,M,D;    Date():Y(0),M(0),D(0){}};istream& operator>>(istream& in, Date& date){    char c;    in>>date.Y>>c>>date.M>>c>>date.D;    return in;}bool isLeapYear(int year){    return (year%400==0 || (year%4==0 && year%100!=0));}int main(){    int T,days;    cin>>T;    Date date;    while(T--)    {        cin>>date;        if(date.M==2 && date.D==29 && !isLeapYear(date.Y+18))        {            cout<<"-1"<<endl;            continue;        }        days = 18*365;        if(date.M<=2 && isLeapYear(date.Y)) days += 1;        for(int i=1;i<18;++i)            if(isLeapYear(date.Y+i)) days += 1;        if(date.M>2 && isLeapYear(date.Y+18)) days += 1;        cout<<days<<endl;    }    return 0;}

java实现:
 
import java.util.Scanner;public class _18岁的生日_hud_1201 {static boolean leap_year(int a){//8969451 2013-08-16 20:44:54 Accepted 1201 109MS 2892K 1870 B Java 1983210400 if( (a%4==0 && a%100!=0) || a%400==0 )    return true;elsereturn false;}public static void main(String[] args) {Scanner sc = new Scanner (System.in);int T = sc.nextInt();while(T-->0){String s = sc.next();int a = Integer.valueOf(s.substring(0 , 4));int b = Integer.valueOf(s.substring(5 , 7));int c = Integer.valueOf(s.substring(8 , 10));int sum = 0;            for(int i=a+1;i<=a+17;i++){            if( leap_year(i) )            sum += 366;                  else                sum += 365;                          }            if(b==2){            if( leap_year(a+18) ){//分类讨论            if( leap_year(a) ){            if(c==29)            sum += 367;//这个重要!!!            else            sum += 366;                       System.out.println(sum);            }            else            System.out.println(sum);//flag                       }            else{            if( leap_year(a) ){                        if(c==29)                       System.out.println(-1);                       else                       System.out.println(sum+366);//flag2                                  }            else                          System.out.println(sum+365);            }            }            else if(b>2){            if(leap_year(a+18))            System.out.println(sum+366);            else            System.out.println(sum+365);                        }            else{            if(leap_year(a))            System.out.println(sum+366);            else            System.out.println(sum+365);            }}}} 

最新消息:5场网络选拔赛的时间初定,详见杭电ACM新浪微博

画8

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3157    Accepted Submission(s): 1396


Problem Description

谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发.

 


 

Input

输入的第一行为一个整数N,表示后面有N组数据.
每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度.

 


 

Output

画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形.
每画一个"8"应空一行,但最前和最后都无空行.

 


 

Sample Input

2A 7B 8 

Sample Output

  AAAA  AAAA  AA  AAAA  AAAA  AA  AA  BBBBB   BBBB   BB  BBBBB   BBBB   BBBB   BB  BBB

 


 

Source

浙江工业大学第四届大学生程序设计竞赛

  

Recommend

JGShining

import java.util.Scanner;public class 画8_2013_08_16_2052 {//89704852013-08-16 22:40:44Accepted1256171MS3360K1274 BJava1983210400public static void main(String[] args) {// TODO Auto-generated method stubScanner sc = new Scanner(System.in);int T = sc.nextInt();while (T-- > 0) {String s = sc.next();int M = sc.nextInt();//System.out.println();int a, b, c, d;if (M == 5) {a = 1;// 横b = 1;// 竖} else {a = M / 2 - 1;b = M / 6 + 1;}c = 2 * b + a;// 宽d = M - (a + 3);for (int i = 1; i <= 2; i++) {for (int j = 1; j <= a + b; j++) {// //if (j <= b)System.out.print(" ");elseSystem.out.print(s);}System.out.println();int e = d;if (i == 2)e = a;for (int k = 1; k <= e; k++) {// /////for (int h = 1; h <=c; h++) {if (h >= b + 1 && h <= a + b)System.out.print(" ");elseSystem.out.print(s);}System.out.println();}if (i == 2) {for (int j = 1; j <= a+b; j++) {// ///////if (j <= b)System.out.print(" ");elseSystem.out.print(s);}//if(T>0)System.out.println();}}if(T>0)//小心PE!!!!!!!!!!!!!!!!!!   System.out.println();}}}


 

Funny Games

Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 0

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

Nils and Mikael are intergalaxial fighters. Now they are competing for the planet Tellus. The size of this small and unimportant planet is 1 < X < 10000 gobs. The problem is that their pockets only have room for one gob, so they have to reduce the size of the planet. They have available 1 <= K <= 6 FACTOR-weapons characterized by numbers F1, F2, . . . , Fk, all less than 0.9. As is commonly known, a FACTOR-weapon will blow off part of the planet, thus reducing the planet to a fraction of its size, given by the characteristic. Thus, with e.g. F1 = 0.5 an application of the first weapon will half the size of the planet. The fighter who reduces the size to less than, or equal to, 1 gob can take the planet home with him. They take turns attacking the planet with any weapon. If Nils starts, who will win the planet? Assume that both Nils and Mikael are omniscient and always make a winning move if there is one. 
Technical note: To ease the problem of rounding errors, there will be no edge cases where an infinitesimal perturbation of the input values would cause a different answer.

Input

The first line of input is N <= 100, the number of test cases. Each of the next N lines consists of X, K and then the K numbers F1, F2, . . . , Fk, having no more than 6 decimals

Output

For each test case, produce one line of output with the name of the winner (either Nils or Mikael).

Sample Input

46 2 0.25 0.510 2 0.25 0.529.29 4 0.3 0.7 0.43 0.5429.30 4 0.3 0.7 0.43 0.54

Sample Output

MikaelNilsNilsMikael

Source

NCPC2005


暂无代码:

Counting Squares

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.

 

Input

 

The input format is a series of lines, each containing 4 integers. Four -1's are used to separate problems, and four -2's are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.

 

Output

 

Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.

 

Sample Input

 

5 8 7 106 9 7 86 8 8 11-1 -1 -1 -10 0 100 10050 75 12 9039 42 57 73-2 -2 -2 -2

 

Sample Output

 

810000

 

Source

 

浙江工业大学第四届大学生程序设计竞赛


暂无代码:

Moving Tables

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 46   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. 



The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving. 



For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.

 

Input

 

The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.

 

Output

 

The output should contain the minimum time in minutes to complete the moving, one per line.

 

Sample Input

 

3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50 

 

Sample Output

 

102030

 

Source

 

Asia 2001, Taejon (South Korea)


暂无代码:

平面上的整点

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 10   Accepted Submission(s) : 0

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

  众所周知,在三维空间内,不共线的三个点可以确定一个平面,现在给出三个点的空间坐标[x1,y1,z1],[x2,y2,z2],[x3,y3,z3],请计算在这3个点确定的平面上坐标分量x, y, z分别在[lx, rx],[ly, ry],[lz,rz]内的整数点有多少个。

 

Input

 

多组测试数据,每组数据包括两行。
第一行是9个整数x1, y1, z1, x2, y2, z2, x3, y3, z3表示三个点的坐标。
第二行有6个整数lx, rx, ly, ry, lz, rz 表示x, y, z的范围。
所有输入数据范围为[-10000, 10000],且
lx<=rx
ly<=ry
lz<=rz

 

Output

 

  对每组测试数据输出一个整数,占一行,在指定定坐标范围内指定平面上有多少个整数点,若输入的三个点不能确定一个平面,直接输出"-1"。

 

Sample Input

 

0 0 0 0 1 0 0 0 1-2 2 -2 2 -2 21 1 1 2 2 2 1 1 1-1 1 -1 1 -1 1

 

Sample Output

 

25-1

 

Hint

 

第二组Sample表示给定的3个点有重合点~

 

Source

 

2013金山西山居创意游戏程序挑战赛——初赛(4)


 

Building bridges

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 2

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

Hululu and Cululu are two pacific ocean countries made up of many islands. These two country has so many years of friendship so they decide to build bridges to connect their islands. Now they want to build the first bridge to connect an island of Hululu and an island of Culuu .
Their world can be considered as a matrix made up of three letters 'H','C' and 'O'.Every 'H' stands for an island of Hululu, every 'C' stands for an island of Cululu, and 'O' stands for the ocean. Here is a example:



The coordinate of the up-left corner is (0,0), and the down-right corner is (4, 3). The x-direction is horizontal, and the y-direction is vertical.
There may be too many options of selecting two islands. To simplify the problem , they come up with some rules below:
1. The distance between the two islands must be as short as possible. If the two islands' coordinates are (x1,y1) and (x2,y2), the distance is |x1-x2|+|y1-y2|.
2. If there are more than one pair of islands satisfied the rule 1, choose the pair in which the Hululu island has the smallest x coordinate. If there are still more than one options, choose the Hululu island which has the smallest y coordinate.
3.After the Hululu island is decided, if there are multiple options for the Cululu island, also make the choice by rule 2. 
Please help their people to build the bridge.

 

Input

 

There are multiple test cases.
In each test case, the first line contains two integers M and N, meaning that the matrix is M×N ( 2<=M,N <= 40).
Next M lines stand for the matrix. Each line has N letters.
The input ends with M = 0 and N = 0.
It's guaranteed that there is a solution.

 

Output

 

For each test case, choose two islands, then print their coordinates in a line in following format:
x1 y1 x2 y2
x1,y1 is the coordinate of Hululu island, x2 ,y2 is the coordinate of Cululu island.

 

Sample Input

 

4 4CHCHHCHCCCCOCOHO5 4OHCHHCHCCCCOCOHOHCHC0 0

 

Sample Output

 

0 1 0 00 1 0 2

 

Source

 

2013ACM-ICPC杭州赛区全国邀请赛


 

Weapon

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

  Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a circle. When it fires, rays form a cylinder that runs through the circle verticality in both side. If one cylinder of rays touch another, there will be an horrific explosion. Originally, all circles can rotate easily. But for some unknown reasons they can not rotate any more. If these weapon can also make an explosion, then Doctor D. is lucky that he can also test the power of the weapon. If not, he would try to make an explosion by other means. One way is to find a medium to connect two cylinder. But he need to know the minimum length of medium he will prepare. When the medium connect the surface of the two cylinder, it may make an explosion.

 

Input

 

  The first line contains an integer T, indicating the number of testcases. For each testcase, the first line contains one integer N(1 < N < 30), the number of weapons. Each of the next 3N lines&#160; contains three float numbers. Every 3 lines represent one weapon. The first line represents the coordinates of center of the circle, and the second line and the third line represent two points in the circle which surrounds the center. It is supposed that these three points are not in one straight line. All float numbers are between -1000000 to 1000000.

 

Output

 

  For each testcase, if there are two cylinder can touch each other, then output 'Lucky', otherwise output then minimum distance of any two cylinders, rounded to two decimals, where distance of two cylinders is the minimum distance of any two point in the surface of two cylinders.

 

Sample Input

 

330 0 01 0 00 0 15 2 25 3 25 2 310 22 -211 22 -111 22 -330 0 01 0 1.51 0 -1.5112 115 109114 112 110109 114 111-110 -121 -130-115 -129 -140-104 -114 -119.80196130 0 01 0 1.51 0 -1.5112 115 109114 112 110109 114 111-110 -121 -130-120 -137 -150-98 -107 -109.603922

 

Sample Output

 

Lucky2.32Lucky

 

Source

 

2013 Multi-University Training Contest 2


 

威威猫系列故事——因式分解

Time Limit : 500/200ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0

Font: Times New Roman | Verdana | Georgia

Font Size:  

Problem Description

 

  “春天来了,万物复苏,大地一片生机盎然,又到了动物们求偶的季节...”
  周末的威威猫虽然眼睛盯着电视屏幕,但是思绪却停留在自己喜欢的数学问题上。
  有人说孤独是可耻的,但是单身一人的威威猫并不孤独,随着对数学的深入学习,威威猫甚至很庆幸自己没有陷入儿女情长,因为他有喜爱的数学相伴,最近,他就在潜心研究因式分解问题。
  在我们学习数学的过程中,经常需要把一个多项式进行因式分解,也就是把它写成乘积的形式,比如多项式x^2+3x+2分解因式的结果就是(x+1)(x+2)。这个因式一眼就能看出来,但是当x的指数更高时,就不太容易分解了。
  现在,威威猫就是在研究如何编写程序来实现对多项式的因式分解。

 

Input

 

  输入第一行是一个整数T(T<=50),表示测试数据的组数;
  接下来是T行字符串表示T个测试用例,每行1个数学多项式,多项式长度不会超过100个字符,每个多项式表示形式如下:

    A[1]x^P[1]+A[2]x^P[2]+...+A[m]x^P[m]

  其中0<=P[i]<=5,A[i]表示x^P[i]的系数,A[i]=0时直接简写为0,A[i]=1和-1时分别简写为x^P[i]与-x^P[i],P[i]=0和1时分别简写为A[i]与A[i]x,且同一指数r的对应项系数之和的绝对值不超过1000, 每行中没有多余空格,具体格式可参考Sample Input。

 

Output

 

  对于每组测试数据,首先输出Case #X: ,X代表多项式编号,从1开始计数,然后输出因式分解的结果,分解结果的表示形式规定如下:
  (x+B[1])(x+B[2])...(x+B[m])
  其中,B[1]<=B[2]<=...<=B[m],若B[i]=0则不加括号直接简写为x,如果无法表现成上述格式,则输出"-1"。
  具体可参考Sample Output。

 

Sample Input

 

4xx+1-2x^2+x^2+x^32x+2

 

Sample Output

 

Case #1: xCase #2: (x+1)Case #3: (x-1)xxCase #4: -1

 

Source

 

2013腾讯编程马拉松初赛第三场(3月23日)
原创粉丝点击