1. 程式人生 > >國慶練習4

國慶練習4

暴力 距離 cas eve axis 最大的 instance als graph

Little C Loves 3 I

Description

Little C loves number «3» very much. He loves all things about it.

Now he has a positive integer nn. He wants to split nn into 33 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 33 integers is a multiple of 33. Help him to find a solution.

Input

A single line containing one integer nn (3n1093≤n≤109) — the integer Little C has.

Output

Print 33 positive integers a,b,ca,b,c in a single line, such that a+b+c=na+b+c=n and none of them is a multiple of 33.

It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

Sample Input

Input
3
Output
1 1 1
Input
233
Output
77 77 79


題目意思:給你一個數n,要求將n分成3分,並且每一份都不能被3整除。
解題思路:直接構造就好了。目的就是為了防止出現劃分出的數是3的倍數,我們就將n按照是不是3的倍數分為兩類。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
6 { 7 int n; 8 int a,b,c; 9 scanf("%d",&n); 10 if(n%3==0) 11 { 12 a=1; 13 b=1; 14 c=n-2; 15 } 16 else if(n%3==1||n%3==2) 17 { 18 a=1; 19 b=2; 20 c=n-3; 21 } 22 printf("%d %d %d\n",a,b,c); 23 return 0; 24 }

Cover Points

Description

There are nn points on the plane, (x1,y1),(x2,y2),,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn).

You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

Input

First line contains one integer nn (1n1051≤n≤105).

Each of the next nn lines contains two integers xixi and yiyi (1xi,yi1091≤xi,yi≤109).

Output

Print the minimum length of the shorter side of the triangle. It can be proved that it‘s always an integer.

Sample Input

Input
3
1 1
1 2
2 1
Output
3
Input
4
1 1
1 2
2 1
2 2
Output
4

Hint

Illustration for the first example: 技術分享圖片

Illustration for the second example: 技術分享圖片



題目意思:求一個能將所有點覆蓋掉的最小等腰三角形的腰長。
解題思路:很水,找一個坐標(x,y),x+y最大的那個點的x+y值即為能夠覆蓋的最小等腰三角形的腰長!可以通過平移得到。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,i,x,y,sum;
 8     int maxs=-9999;
 9     scanf("%d",&n);
10     for(i=1; i<=n; i++)
11     {
12         scanf("%d%d",&x,&y);
13         sum=x+y;
14         if(sum>maxs)
15         {
16             maxs=sum;
17         }
18     }
19     printf("%d\n",maxs);
20     return 0;
21 }



Description

Karen is getting ready for a new school day!

技術分享圖片

It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.

What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?

Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.



Input

The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).



Output

Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.



Sample Input

Input
05:39
Output
11
Input
13:31
Output
0
Input
23:59
Output
1


Hint

In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.

In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.

In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.


題目意思:女主角要在回文時刻起床,給你一個時刻,問到距離下一個回文時刻,女主角還能睡多久。
解題思路:開始我一直在找小時和分鐘關於回文的對稱關系,希望能找到規律,後來一直出錯,因為會有小時進位問題,後來改成直接暴力模擬,AC。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char s[10];
 6 int main()
 7 {
 8     int h,m,a,b;
 9     int ans;
10     gets(s);
11     h=s[1]-0+(s[0]-0)*10;
12     m=s[4]-0+(s[3]-0)*10;
13     ans=0;
14     //printf("%d %d\n",h,m);
15     while(1)
16     {
17         if(m%10==h/10&&h%10==m/10)///該起床了
18         {
19             break;
20         }
21         m++;
22         ans++;
23         if(m==60)
24         {
25             m=0;
26             h++;
27         }
28         if(h==24)
29         {
30             h=0;
31         }
32     }
33     printf("%d\n",ans);
34     return 0;
35 }



國慶練習4