您的位置:首页 > 其它

HPU ACM15级周练

2015-12-03 20:43 288 查看
A - A
Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.



(The numbers in the grids stand for the time when the corresponding cell lights up)
In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.

Output

For each case you have to print the case number and two numbers (x, y), the column and the row number.

Sample Input

3

8

20

25

Sample Output

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5

水题,看结构找规律:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
long long a,b,i,j,n,l,r,mid,x,y,cot=1,t;
scanf("%lld",&n);
while(n--)
{
int flag=0;
scanf("%lld",&a);
t=sqrt(a);
if(t*t==a)
{
if(t%2)
{
x=1;
y=t;
}
else
{
y=1;
x=t;
}
printf("Case %lld: %lld %lld\n",cot++,x,y);
continue;
}

if(t%2==0)
{
j=a-t*t;
if(j<(t+1))
{
x=t+1;
y=j;
}
else
{
x=t+1-j%(t+1);
y=t+1;
}
}
else
{

j=a-t*t;
if(j<t+1)
{
y=t+1;
x=j;
}
else
{
y=t+1-j%(t+1);
x=t+1;
}
}
printf("Case %lld: %lld %lld\n",cot++,x,y);
}
return 0;
}


B - B
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a sequence of only a digit. Now you are given the number and the only allowable digit, you should report the number of digits of such multiple.

For example you have to find a multiple of 3 which contains only 1's. Then the result is 3 because is 111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7 which contains only 3's then, the result is 6, because 333333 is divisible
by 7.

Input

Input starts with an integer T (≤ 300), denoting the number of test cases.

Each case will contain two integers n (0 < n ≤ 106 and n will not be divisible by 2 or 5) and the allowable digit (1 ≤ digit ≤ 9).

Output

For each case, print the case number and the number of digits of such multiple. If several solutions are there; report the minimum one.

Sample Input

3

3 1

7 3

9901 1

Sample Output

Case 1: 3

Case 2: 6

Case 3: 12

简单数学题,说是同余定理那么高大上简直就是敷衍自己不会做,不算是同余定理
#include<stdio.h>
#include<string.h>
long long i,j,k,l,m,n;
int main()
{
int flag=1;
scanf("%lld",&k);
while(k--)
{
scanf("%lld%ldd",&m,&n);
long long ans=1;
l=n;
while(l%m)
{
l=l%m*10+n;
ans++;
}
printf("Case %d: %lld\n",flag++,ans);
}
}


C - C
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

Ekka and his friend Dokka decided to buy a cake. They both love cakes and that's why they want to share the cake after buying it. As the name suggested that Ekka is very fond of odd numbers and Dokka is very fond of even numbers, they want to divide the
cake such that Ekka gets a share ofN square centimeters and Dokka gets a share of M square centimeters where N is odd and M is even. Both N and M are positive
integers.

They want to divide the cake such that N * M = W, where W is the dashing factor set by them. Now you know their dashing factor, you have to find whether they can buy the desired cake or not.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer W (2 ≤ W < 263). And W will not be a power of 2.

Output

For each case, print the case number first. After that print "Impossible" if they can't buy their desired cake. If they can buy such a cake, you have to print N and M. If there are multiple solutions, then
print the result where M is as small as possible.

Sample Input

3

10

5

12

Sample Output

Case 1: 5 2

Case 2: Impossible

Case 3: 3 4

做的时候傻逼了一下,超时了,马上就改过来了:
<pre name="code" class="cpp">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long i,j,k,l,m,n;
int main()
{
int flag=1;
scanf("%lld",&j);
while(j--)
{
scanf("%lld",&m);
if(m&1)
printf("Case %d: Impossible\n",flag++);
else
{
k=m/2;
n=2;
while(k%2==0)
{
k/=2;
n*=2;
}
printf("Case %d: %lld %lld\n",flag++,k,n);
}
}
}




D - D
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if
there exists an integer c such that a = b * c.

Input

Input starts with an integer T (≤ 525), denoting the number of test cases.

Each case starts with a line containing two integers a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). Numbers will not contain leading zeroes.

Output

For each case, print the case number first. Then print 'divisible' if a is divisible by b. Otherwise print 'not divisible'.

Sample Input

6

101 101

0 67

-101 101

7678123668327637674887634 101

11010000000000000000 256

-202202202202000202202202 -101

Sample Output

Case 1: divisible

Case 2: divisible

Case 3: divisible

Case 4: not divisible

Case 5: divisible

Case 6: divisible

跟第二题差不多,一样的思路:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[110000];
long long i,j,k,l,m,n,t,p,sum,cnt=1;
int main()
{
scanf("%lld",&p);
while(p--)
{
int flag=0;
scanf("%s%lld",s,&m);
l=strlen(s);
sum=0;
for(i=0;i<l;i++)
{
if(s[i]<='9'&&s[i]>='0')
sum=(sum*10+(s[i]-'0'))%m;
}
if(sum)
printf("Case %lld: not divisible\n",cnt++);
else
printf("Case %lld: divisible\n",cnt++);
}
}

E - E
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

A group of N Internet Service Provider companies (ISPs) use a private communication channel that has a maximum capacity of C traffic units per second. Each company transfers T traffic units per second through
the channel and gets a profit that is directly proportional to the factor T(C - T*N). The problem is to compute the smallest value of T that maximizes the total profit the N ISPs can get from using the channel.
Notice that N, C, T, and the optimal T are integer numbers.

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a line containing two integers N and C (0 ≤ N, C ≤ 109).

Output

For each case, print the case number and the minimum possible value of T that maximizes the total profit. The result should be an integer.

Sample Input

6

1 0

0 1

4 3

2 8

3 27

25 1000000000

Sample Output

Case 1: 0

Case 2: 0

Case 3: 0

Case 4: 2

Case 5: 4

Case 6: 20000000

这题至今还没有翻译,真是看不懂,日后在A,不过好像是poj上边的题,先跳过

F - F
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status

Description

Given two integers: n and m and n is divisible by 2m, you have to write down the first n natural numbers in the following form. At first take first mintegers
and make their sign negative, then take next m integers and make their sign positive, the next m integers should have negative signs and continue this procedure until all the n integers have been assigned
a sign. For example, let n be 12 and m be 3. Then we have

-1 -2 -3 +4 +5 +6 -7 -8 -9 +10 +11 +12

If n = 4 and m = 1, then we have

-1 +2 -3 +4

Now your task is to find the summation of the numbers considering their signs.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing two integers: n and m (2 ≤ n ≤ 109, 1 ≤ m). And you can assume that n is divisible by 2*m.

Output

For each case, print the case number and the summation.

Sample Input

2

12 3

4 1

Sample Output

Case 1: 18

Case 2: 2

也不算难吧,这几道题难度都差不多,偏数学了一点:

#include<stdio.h>
#include<string.h>
long long i,j,k,l,m,n,p,flag=1;
int main()
{
scanf("%lld",&p);
while(p--)
{
scanf("%lld%lld",&m,&n);
l=0;
j=m/(2*n);
l+=n*n*j;
j=j*n*2;
int cnt=0;
for(i=j+1;i<=m;i++)
{
l-=i;
cnt++;
if(cnt==n)
break;
}
i++;
for(;i<=m;i++)
l+=i;
printf("Case %lld: %lld\n",flag++,l);
}
}
<div class="plm" style="text-align: center; font-size: 12pt; color: rgb(34, 34, 34); clear: both;"><div class="ptt" id="problem_title" style="font-size: 18pt; font-weight: bold; color: blue; padding: 10px;"><span style="color: green;">G - </span>G</div><span id="crawlSuccess" class="crawlInfo" style="display: inline;"><strong>Time Limit:</strong><span id="timeLimit">1000</span>MS     <strong>Memory Limit:</strong><span id="memoryLimit">32768</span>KB     <strong>64bit IO Format:</strong><span id="_64IOFormat">%I64d & %I64u</span></span><div id="problem_opt" style="font-size: 12px; margin-top: 10px;"><a target=_blank id="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" style="display: inline-block; position: relative; padding: 0px; margin-right: 0.1em; cursor: pointer; vertical-align: middle; overflow: visible; font-family: Verdana, Arial, sans-serif; font-size: 1em; border: 1px solid rgb(211, 211, 211); color: rgb(85, 85, 85); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; background: url(http://acm.hust.edu.cn/vjudge/jquery-ui-1.11.1.custom/images/ui-bg_glass_75_e3e4f8_1x400.png) 50% 50% repeat-x rgb(227, 228, 248);"><span class="ui-button-text" style="display: block; padding: 0.4em 1em;">Submit</span></a> <a target=_blank id="problem_status" href="http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101018#status//G/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" style="display: inline-block; position: relative; padding: 0px; margin-right: 0.1em; cursor: pointer; vertical-align: middle; overflow: visible; text-decoration: none; font-family: Verdana, Arial, sans-serif; font-size: 1em; border: 1px solid rgb(211, 211, 211); color: rgb(85, 85, 85); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; background: url(http://acm.hust.edu.cn/vjudge/jquery-ui-1.11.1.custom/images/ui-bg_glass_75_e3e4f8_1x400.png) 50% 50% repeat-x rgb(227, 228, 248);"><span class="ui-button-text" style="display: block; padding: 0.4em 1em;">Status</span></a></div></div><div style="color: rgb(34, 34, 34); font-family: Verdana, Arial, sans-serif; font-size: 14px; width: 960px; margin: auto;"><div class="hiddable" id="vj_description" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Description</p><div class="textBG" style="border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px; background-color: rgb(234, 235, 255);"><div class="panel_content">WhereIsHeroFrom:             Zty, what are you doing ? 
Zty:                                     I want to calculate N!...... 
WhereIsHeroFrom:             So easy! How big N is ? 
Zty:                                    1 <=N <=1000000000000000000000000000000000000000000000… 
WhereIsHeroFrom:             Oh! You must be crazy! Are you Fa Shao? 
Zty:                                     No. I haven's finished my saying. I just said I want to calculate N! mod 2009 

Hint : 0! = 1, N! = N*(N-1)! 
</div><div class="panel_bottom"> </div></div></div><div class="hiddable" id="vj_input" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Input</p><div class="textBG" style="border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px; background-color: rgb(234, 235, 255);"><div class="panel_content">Each line will contain one integer N(0 <= N<=10^9). Process to end of file. 
</div><div class="panel_bottom"> </div></div></div><div class="hiddable" id="vj_output" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Output</p><div class="textBG" style="border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px; background-color: rgb(234, 235, 255);"><div class="panel_content">For each case, output N! mod 2009 
</div><div class="panel_bottom"> </div></div></div><div class="hiddable" id="vj_sampleInput" style="font-family: 'times new roman'; font-size: 17px;"><p class="pst" style="font-family: Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold; color: blue; margin-bottom: 0px;">Sample Input</p><div class="textBG" style="border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; padding: 10px; border-style: dotted; border-width: 2px; background-color: rgb(234, 235, 255);"><div class="panel_content"><pre style="white-space: pre-wrap; word-wrap: break-word;"><div style="font-family: 'Courier New', Courier, monospace;">4
5 </div>


 

Sample Output

24
120

 



附代码:
#include<stdio.h>
#include<string.h>
long long i,j,k,l,m,n;
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n>=49)
printf("0\n");
else
{
m=1;
for(i=1;i<=n;i++)
m=m*i%2009;
printf("%lld\n",m);
}
}
}

H - H
Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d
& %I64u
Submit Status

Description

The Annual National Olympic of Information(NOI) will be held.The province of Shandong hold a Select(which we call SDOI for short) to choose some people to go to the NOI. $ n ( n \leq 100 )$ people comes to the Select and there is
$ m (m \leq 50)$ people who can go to the NOI. 

According to the tradition and regulation.There were two rounds of the SDOI, they are so called "Round 1" and "Round 2", the full marks of each round is $300$. 

All the n people take part in Round1 and Round2, now the original mark of every person is known. The rule of SDOI of ranking gets to the "standard mark". For each round there is a highest original mark,let's assume that is $x$.(it is promised that not all person
in one round is 0,in another way,$x > 0$). So for this round,everyone's final mark equals to his/her original $mark * ( 300 / x )$. 

After we got everyone's final mark in both round.We calculate the Ultimate mark of everyone as $0.3 * round1's$ final mark + $0.7 * round2's$ final mark.It is so great that there were no two persons who have the same Ultimate mark. 

After we got everyone's Ultimate mark.We choose the persons as followed: 

To encourage girls to take part in the Olympic of Information.In each province,there has to be a girl in its teams. 

1. If there is no girls take part in SDOI,The boys with the rank of first m enter the team. 

2. If there is girls, then the girl who had the highest score(compared with other girls) enter the team,and other(boys and other girls) m-1 people with the highest mark enter the team. 

Just now all the examination had been finished.Please write a program, according to the input information of every people(Name, Sex ,The original mark of Round1 and Round2),Output the List of who can enter the team with their Ultimate mark decreasing. 

 

Input

There is an integer $T(T \leq 100)$ in the first line for the number of testcases and followed $T$ testcases. 

For each testcase, there are two integers $n$ and $m$ in the first line$(n \geq m)$, standing for the number of people take part in SDOI and the allowance of the team.Followed with $n$ lines,each line is an information of a person. Name(A string with length
less than $20$,only contain numbers and English letters),Sex(male or female),the Original mark of Round1 and Round2 (both equal to or less than $300$) separated with a space. 

 

Output

For each testcase, output "The member list of Shandong team is as follows:" without Quotation marks. 

Followed $m$ lines,every line is the name of the team with their Ultimate mark decreasing.
 

Sample Input

2
10 8
dxy male 230 225
davidwang male 218 235
evensgn male 150 175
tpkuangmo female 34 21
guncuye male 5 15
faebdc male 245 250
lavender female 220 216
qmqmqm male 250 245
davidlee male 240 160
dxymeizi female 205 190
2 1
dxy male 300 300
dxymeizi female 0 0

 

Sample Output

The member list of Shandong team is as follows:
faebdc
qmqmqm
davidwang
dxy
lavender
dxymeizi
davidlee
evensgn
The member list of Shandong team is as follows:
dxymeizi

Hint
For the first testcase: the highest mark of Round1 if 250,so every one's mark times(300/250)=1.2, it's same to Round2.
The Final of The Ultimate score is as followed
faebdc 298.20
qmqmqm 295.80
davidwang 275.88
dxy 271.80
lavender 260.64
dxymeizi 233.40
davidlee 220.80
evensgn 201.00
tpkuangmo 29.88
guncuye 14.40

For the second testcase,There is a girl and the girl with the highest mark dxymeizi enter the team, dxy who with the highest mark,poorly,can not enter the team.

 

结构体排序,学姐说是bc上边的题:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
char name[1100];
int sex;
double mark1;//round 1
double mark2;//round 2
double mark3;//scoor;
}t[110000];
int cmp(node a,node b)
{
return a.mark3 > b.mark3;
}
int i,j,p,m,n,k,l,help;
char s[110];
int main()
{
scanf("%d",&p);
while(p--)
{
scanf("%d%d",&m,&n);
double Max1=0;
double Max2=0;
for(i=0;i<m;i++)
{
scanf("%s%s%lf%lf",t[i].name,s,&t[i].mark1,&t[i].mark2);
if(s[0]=='f')
t[i].sex=0;//gorl
else
t[i].sex=1;//boy
Max1=max(Max1,t[i].mark1);
Max2=max(Max2,t[i].mark2);
}
for(i=0;i<m;i++)
t[i].mark3=t[i].mark1*300/Max1*0.3+t[i].mark2*300/Max2*0.7;
sort(t,t+m,cmp);
int flag=0;
help=-1;
for(i=0;i<n;i++)
if(t[i].sex==0)
flag=1;
for(i=0;i<m;i++)
if(t[i].sex==0)
{
help=i;
break;
}
printf("The member list of Shandong team is as follows:\n");

//
// for(i=0;i<m;i++)
// printf("+++%lf\n",t[i].mark3)
if(flag||help==-1)//木有女生或者女生已经选上
for(i=0;i<n;i++)
printf("%s\n",t[i].name);
else//有女生但是没选上
{
for(i=0;i<n-1;i++)
printf("%s\n",t[i].name);
printf("%s\n",t[help].name);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hpu 周练