杭电acm题目水题英文题目、翻译及ac源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1040 As Easy As A+B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 26015 Accepted Submission(s): 11054
Problem Description
These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
Give you some integers, your task is to sort these number ascending (升序).
You should know how easy the problem is now!
Good luck!
Input
Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.
It is guarantied that all integers are in the range of 32-int.
Output
For each case, print the sorting result, and one line one case.
问题描述
这些天来,我在思考一个问题,我怎样才能得到一个简单的问题,因为A + B?这是相当困难做这样的事情。
当然,我得到了它之后,许多清醒的夜晚,
给你一些整数,你的任务就是这些数字升序(升序)排序。
你应该知道,现在的问题是多么容易!
祝你好运
输入
输入包含多个测试案例。
输入的第一行是一个整数T,它是多的测试用例。
T检验的情况下,遵循。
每个测试案例都包含一个整数N(1 <= N <= 1000的整数的个数进行排序),然后在同一行N个整数。
消费“,所有的整数都在32整数的范围。
产量
对于每一种情况下,打印的排序结果,一行一个案例。
2
3 2 1 3
9 1 4 7 2 5 8 3 6 9
样本输出
1 2 3
1 2 3 4 5 6 7 8 9
最后一个数字后面没有空格的!
#include<stdio.h>
int main()
{
int a,b,d,n,m,i,j,t,k;
int c[2000];
scanf("%d",&a);
for(n=0;n<a;n++)
{
scanf("%d",&b);
for(m=0;m<b;m++)
{
scanf("%d",&d);
c[m]=d;
}
for(i=1;i<b;i++)
{
for(j=1;j<=(b-i);j++)
{
if(c[j-1]>c[j])
{
t=c[j];
c[j]=c[j-1];
c[j-1]=t;
}
else
continue;
}
}
for(k=0;k<b;k++)
{
if(k==(b-1))
printf("%d\n",c[k]);
else
printf("%d ",c[k]);
}
}
return 0;
}
1032 The 3n + 1 problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15157 Accepted Submission(s): 5577
Problem Description
Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.
Consider the following algorithm:
1. input n
2. print n
3. if n = 1 then STOP
4. if n is odd then n <- 3n + 1
5. else n <- n / 2
6. GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
Input
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
You can assume that no opperation overflows a 32-bit integer.
Output
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
这个题很水,主要是题意。
还这个题涉及到了3*n+1问题:
3n+1问题是一个简单有趣而又没有解决的数学问题。
这个问题是由L. Collatz在1937年提出的。
克拉兹问题(Collatz problem)也被叫做hailstone问题、3n+1问题、Hasse算法问题、Kakutani 算法问题、Thwaites猜想或者Ulam问题。
问题如下:
(1)输入一个正整数n;
(2)如果n=1则结束;
(3)如果n是奇数,则n变为3n+1,否则n变为n/2;
(4)转入第(2)步。
克拉兹问题的特殊之处在于:尽管很容易将这个问题讲清楚,但直到今天仍不能保证这个问题的算法对所有可能的输入都有效——即至今没有人证明对所有的正整数该过程都终止。
题意:
题的大意是输入两个数(注意,这里没有说第一个数一定要小与第二个数),然后对这两个数之间的所有整数包括端点的数,进行一种规律运算,并求出运算的次数,比较所有的数规律运算次数,输出最大的.
#include <stdio.h>
int main(int argc, char *argv[])
{
int a,b;
while (scanf ("%d %d",&a,&b) != EOF)
{
int i,j,flag=0,len=0,max = 0;
if (a>b)
{
i=a;
a=b;
b=i;
flag=1;
}
for (i=a;i<=b;i++)
{
for (j=i,len=1;j!=1;)
{
if (j%2!=0)
j = 3*j+1;
else
j = j/2;
len++;
}
if (len>max)
max = len;
}
if (flag == 1)
{
i = a;
a = b;
b = i;
}
printf ("%d %d %d\n",a,b,max);
}
return 0;
}
Sample Input
1 10
100 200
201 210
900 1000
`````` Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
1048 The Hardest Problem Ever
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11647 Accepted Submission(s): 5273
Problem Description
Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked.
You are a sub captain of Caesar's army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is 'A', the cipher text would be 'F'). Since you are creating plain text out of Caesar's messages, you will do the opposite:
Cipher text
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Plain text
V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
朱利叶斯·凯撒生活在危险和阴谋的时间。
恺撒以往任何时候都面临着最困难的情况下保持自己活着。
为了他的生存,他决定创建的第一个密码。
此密码是如此的令人难以置信的声音,没有人能弄清楚,不知道它是如何工作的。
你是一个分队长,恺撒的军队。
这是你的工作,这些消息进行解密发送的凯撒,并提供您的一般。
代码很简单。
对于一个明文消息中的每个字母,你将它转移五个地方的权利,以创建安全的消息(即,如果这封信是'A',密文将'F')。
由于您要创建纯文本凯撒的消息,你会做相反的:在这个加密密文的一个BCDEFGHIJKLMNOPQRSTUV WXYZ 纯文本V WXYZABCDEFGHIJKLMNOPQ RSTU 只有字母被转移。
任何非字母字符保持不变,所有字母字符将是大写字
输入
输入到这个问题,将包括一个(非空)系列高达100的数据集。
每个数据集将被格式化,根据下面的描述中,将不会有空白行分离数据集。
所有字符都将是大写的。
一个数据集有3个部分组成:起始线-一个单一的线,“开始” 加密消息- A一行包含200个字符,包括从凯撒端线,包括一个单一的消息-单行线,“END” 的最终数据集将是一个单一的,“ENDOFINPUT”。
产量
为每个数据集,将是完全有一行输出。
这是凯撒的原始消息。
//
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.
A single data set has 3 components:
Start line - A single line, "START"
Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar
End line - A single line, "END"
Following the final data set will be a single line, "ENDOFINPUT".
Output
For each data set, there will be exactly one line of output. This is the original message by Caesar. Sample Input
START NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX END START N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ END START IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ END ENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
scanf()改gets()就过了!
#include<stdio.h>
#include<string.h>
int main()
{
int i,n;
char s[500];
while(gets(s))
{
if(strcmp(s,"START")==0)
continue;
if(strcmp(s,"END")==0)
continue;
if(strcmp(s,"ENDOFINPUT")==0)
break;
n=strlen(s);
for(i=0;i<n;i++)
{
if(s[i]>='F')
s[i]-=5;
else if(s[i]>='A'&&s[i]<'F')
s[i]+=21;
else
s[i]=s[i];
printf("%c",s[i]);
}
printf("\n");
}
return 0;
}
1076 An Easy Task
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10297 Accepted Submission(s): 6421
Problem Description
Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?
Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from year Y.
Note: if year Y is a leap year, then the 1st leap year is year Y.
Input
The input contains several test cases. The first line of the input is a single integer T which is the
number of test cases. T test cases follow.
Each test case contains two positive integers Y and N(1<=N<=10000). Output
For each test case, you should output the Nth leap year from year Y. Sample Input
3 2005 25 1855 12 200
4 10000
Sample Output
2108 1904 43236
Hint
We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0. #include <stdio.h>
int main()
{
int a,y,c,i,j,s;
scanf ("%d",&a);
for (j=0;j<a;j++)
{
scanf("%d %d",&y,&c);
s=0;
for (i=y;i>0;i++)
{
if((i%4==0&&i%100!=0)||(i%400==0))
s++;
if(s==c) break;
}
printf ("%d\n",i);
}
return 0;
}
2101
#include<stdio.h>
int isr(int x){
if((x %4 ==0 && x % 100!=0)|| x %400==0) return 366;
return 365;
}
main()
{
int y,m,d;
int sum,i,t,n;
scanf("%d",&n);
while(n--)
{
scanf("%d-%d-%d",&y,&m,&d);
t=0;
sum =0;
for(i=y+1;i<y+18;i++)
{
sum+=isr(i);
}
if(isr(y+18)==365 && m==2 && d==29 ){
printf("-1\n");
}else{
if(isr(y+18)== 366)
{
if(m>2 ||(m==2 && d==29))
t++;
}
if(isr(y)== 366)
{
if((m==2 && d <=29)||m<2)
t++;
}
printf("%d\n",sum+365+t);
}
}
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7689 Accepted Submission(s): 3192
Problem Description
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:
(a) The setup time for the first wooden stick is 1 minute.
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.
You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).
Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.
Output
The output should contain the minimum setup time in minutes, one per line.
Sample Input
3 5
4 9
5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1 Sample Output
2 1 3
贪心加排序
/*2010-08-14 15:33:59 Accepted 1051 15MS 288K 817 B C++ */
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct stick
{
int l,h;
}a[5005];
bool f[5005];
int cmp(stick x,stick y)
{
if(x.l!=y.l) return x.l<y.l;
return x.h<y.h;
}
int main()
{
int T,n,i,j,temp;
cin>>T;
while(T--)
{
cin>>n;
for(i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].h), f[i]=0; sort(a+1,a+n+1,cmp);
int count=0;
for(i=1;i<=n;i++) //长度已经是顺序的了;
{
if(f[i]) continue;
temp=a[i].h;
for(j=i+1;j<=n;j++)
{
if(f[j]==0&&temp<=a[j].h)
{
temp=a[j].h;
f[j]=1;
}
}
count++;
}
printf("%d\n",count);
}
}
HangOver
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7090 Accepted Submission(s): 2848
Problem Description
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.00 3.71 0.04 5.19 0.00
Sample Output
3 card(s) 61 card(s) 1 card(s) 273 card(s)
宿醉
时间限制:2000/1000 MS(Java /其他)内存限制:三万二千七百六十八分之六万五千五百三十六K(Java /其他的)
总提交(S):7090接受提交的文件:2848
问题描述
卡悬一摞表,你能走多远?如果你有一个卡,你可以创建一个最大的悬一卡长度的一半。
(我们假设该卡必须垂直于工作台。
)有两个卡,就可以使顶牌悬一卡长度的一半,底部和底部悬在表的卡长度的三分之一,为1/2 + 1/3 = 5/6卡长度的总的最大突出部分。
一般来说,你可以让N卡过剩1/2 + 1/3 + 1/4 + ... + 1 /(n +1)的卡的长度,顶端卡出挑由1/2的第二个,所述第二突出末端三分之一的塔第三,第三出挑的第四个1/4,等,和底部卡出挑的表由1 /(n +1)个。
这在下面的图所示,输入由一个或多个测试的情况下,随后由含的线端的输入信号的数量0.00。
每个测试案例是单行含有浮点正数c的值是至少为0.01,至多5.20; c将包含完全相同三位数。
对于每个测试用例,输出的最小数目的卡,要实现一个悬至少C卡的长度。
使用实施例中示出的精确的输出格式。
样例输入
1.00 3.71 0.04 5.19 0.00
样本输出
3卡(S)61卡(S)1卡(S)273卡(S)
可能是for(i=2;sum<x;i++)//我原来是<=
用数据0.5测试应该是1
#include<stdio.h>
int main()
{
double x,sum,i;
int j;
while(scanf("%lf",&x)!=EOF&&x!=0.00)
{
sum=0,j=0;
for(i=2;sum<x;i++)
{
sum+=1/i;
j++;
}
printf("%d card(s)n",j);
}
return 0;
}
建议不用减,用加,然后比较或者存个300的数组,比较
1058 Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11380 Accepted Submission(s): 4959
Problem Description
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.
Write a program to find and print the nth element in this sequence
Input
The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n
<= 5842. Input is terminated by a value of zero (0) for n.
Output
For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output.
Sample Input
1 2 3 4 11 12 13 21 22 23 100 1000 5842 0
Sample Output
The 1st humble number is 1. The 2nd humble number is 2. The 3rd humble number is 3. The 4th humble number is 4. The 11th humble number is 12. The 12th humble number is 14. The 13th humble number is 15. The 21st humble number is 28. The 22nd humble number is 30. The 23rd humble number is 32. The 100th humble number is 450. The 1000th humble number is 385875. The 5842nd humble number is 2000000000.
谦卑号
时间限制:2000/1000 MS(Java /其他)内存限制:三万二千七百六十八分之六万五千五百三十六K(Java /其他的)
总提交(S):11380接受的提交(S):4959
问题描述
一个数,其首要因素是2,3,5或7被调用一个不起眼的数量。
序列1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,... 前20个不起眼的数字。
写一个程序来查找和打印此序列中的第n个元素
输入
输入由一个或多个测试用例。
每个测试案例是由一个整数n,1 <= N <= 5842。
输入结束的值为零(0),其中n。
产量
对于每个测试案例,打印一行“的第n个不起眼的数字是数字。
”。
根据n时,正确的后缀st 的“,”第二“,”第三届“,或”th“的序数的第n的值可用于像,它是显示在样品输出。
样例输入
1234111213212223100100058420
样本输出
第一个不起眼的数量为1。
第二个不起眼的数字是2。
第三不起眼的数字是3。
第四谦卑的数字是4。
第11届不起眼的数量为12个。
第12届谦卑的数字是14。
第13届不起眼的号码是15。
21谦卑的数字是28。
第22届谦卑的数字是30。
第23届不起眼的数量为32个。
第100谦卑的数字是450。
1000谦卑的数字是385875。
第五千八百四十二不起眼的数字是20亿。
11,12,13(包括后两位是这3数的,如113,213,313,413等等)后面是加th,
剩下的末位是1,2,3的话加的是st,nd,rd(如1,21,321,331,341)
用代码说出来似乎更简单
if(n%10==1&&n%100!=11) 加st
else if(n%10==2&&n%100!=12) 加nd
else if(n%10==3&&n%100!=13) 加rd
else 加th
希望能帮助大家少走弯路,至于算法不提大家自己琢磨吧,只是觉得这道题在纯英语规则上浪费时间不那
么太值
#include<stdio.h>
__int64 array[6001];
int arraynum;
int init()
{
arraynum=0;
for(int i=1;i<=7;i++)
array[++arraynum]=i;
while(1)
{
__int64 temp=(__int64)1<<62;
for(int j=1;j<=arraynum;j++)
{
for(int z=2;z<=7;z++)
{
if(z*array[j]<temp&&z*array[j]>array[arraynum]) temp=z*array[j];
}
}
array[++arraynum]=temp;
if(arraynum>5842)
return 0;
}
return 0;
}
int main()
{
init();
int n;
while(scanf("%d",&n)!=EOF&&n!=0)
{
if(n%10==1&&n%100!=11)
printf("The %dst humble number is ",n);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is ",n);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is ",n);
else
printf("The %dth humble number is ",n);
printf("%d.\n",array[n]);
}
return 0;
}。