标签库元素:
队列<queue> FIFO
栈 <stack> FICO
集合 set
不定长数组 vector
映射 map
Maximum Multiple
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3985 Accepted Submission(s): 926
Problem Description
Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y, x∣n, y, z and xy is maximum.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤106).
The first line contains an integer n (1≤n≤106).
Output
For each test case, output an integer denoting the maximum xy. If there no such integers, output −1 instead.
Sample Input
3
1
2
3
Sample Output
-1 -1 1
1 #include<iostream> 2 #include<vector> 3 #include<stdio.h> 4 using namespace std; 5 6 int main() 7 { 8 long long n; 9 int t ; 10 cin>>t; 11 while(t--) 12 { 13 scanf("%lld",&n); 14 if(n%3 == 0) cout<<(n/3)*(n/3)*(n/3)<<endl; 15 else 16 { 17 if(n%4 == 0) cout<<(n/2)*(n/4)*(n/4)<<endl; 18 else cout<<-1<<endl; 19 } 20 21 } 22 return 0; 23 }
Triangle Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 2140 Accepted Submission(s): 925
Special Judge
Problem Description
Chiaki has 3n points p1,p2,…,p3n. It is guaranteed that no three points are collinear.
Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.
Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1000) -- the number of triangle to construct.
Each of the next 3n lines contains two integers xi and y (−109≤xi,y).
It is guaranteed that the sum of all n does not exceed 10000.
The first line contains an integer n (1≤n≤1000) -- the number of triangle to construct.
Each of the next 3n lines contains two integers xi and y (−109≤xi,y).
It is guaranteed that the sum of all n does not exceed 10000.
Output
For each test case, output n lines contain three integers ai,bi,ci (1≤ai,bi,ci≤3n) each denoting the indices of points the i-th triangle use. If there are multiple solutions, you can output any of them.
Sample Input
1
1
1 2
2 3
3 5
Sample Output
1 2 3
1 #include<iostream> 2 #include<vector> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 struct P 7 { 8 long long x,y; 9 int id; 10 }p[3000+10]; 11 int cmp(P a,P b) 12 { 13 return a.x<b.x; 14 } 15 16 int main() 17 { 18 19 int t; 20 cin>>t; 21 while(t--) 22 { 23 int n ; 24 cin>>n; 25 for(int i = 1;i <= 3*n;i++) 26 { 27 scanf("%lld %lld",&p[i].x,&p[i].y); 28 p[i].id = i; 29 } 30 sort(p+1,p+3*n+1,cmp); 31 32 for(int i = 1;i<=3*n;i++) 33 { 34 35 cout<<p[i].id; 36 if(i%3 == 0) cout<<endl; 37 else cout<<" "; 38 } 39 } 40 return 0; 41 }
Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5204 Accepted Submission(s): 878
Problem Description
Chiaki often participates in international competitive programming contests. The time zone becomes a big problem.
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T), indicating the number of test cases. For each test case:
The first line contains two integers a, b (0≤a≤23,0≤b≤59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0≤X).
The first line contains two integers a, b (0≤a≤23,0≤b≤59) and a string s in the format of "UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' (0≤X).
Output
For each test, output the time in the format of hh:mm (24-hour clock).
Sample Input
3
11 11 UTC+8
11 12 UTC+9
11 23 UTC+0
Sample Output
11:11
12:12
03:23
1 #include <bits/stdc++.h> 2 #include <vector> 3 #include <queue> 4 5 using namespace std; 6 7 int main() 8 { 9 int t; 10 scanf("%d",&t); 11 while(t--) 12 { 13 int a,b; 14 char f; 15 double k; 16 int q=0; 17 scanf("%d %d UTC%c%lf",&a,&b,&f,&k); 18 k=k*10; 19 int m1=((int)k%10)*6; 20 int h1=(int)k/10; 21 a=(a-8+24)%24; 22 23 if(f=='+') 24 { 25 if(b+m1>=60) 26 { 27 q=1; 28 } 29 else q=0; 30 m1=(b+m1)%60; 31 h1=(a+q+h1)%24; 32 } 33 else if(f=='-') 34 { 35 if(m1>b) 36 { 37 q=1; 38 } 39 else q=0; 40 41 m1=(b+60-m1)%60; 42 43 h1=(a-q-h1+24)%24; 44 45 } 46 if(h1<=9) 47 { 48 printf("0%d:",h1); 49 } 50 else printf("%d:",h1); 51 52 if(m1<=9) 53 { 54 printf("0%d ",m1); 55 } 56 else printf("%d ",m1); 57 58 } 59 60 61 return 0; 62 }