Maximum Multiple
Problem Description
Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤106).
Output
For each test case, output an integer denoting the maximum xyz. If there no such integers, output −1 instead.
Sample Input
3
1
2
3
Sample Output
-1
-1
1
被三整除一定是三个数相等,其次是被2整除且被四整除的数可取
s=2x1;
s=4x2;
s=x1+2x2
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) ((a,0,sizeof(a))) typedef long long ll; ll n,t; int main() { scanf("%lld",&t); while(t--) { scanf("%lld",&n); if(n<=2) {printf("-1\n");continue;} ll k=n/3; if(n%3==0) printf("%lld\n",k*k*k); else { ll k=n/2; ll m=k/2; if(m+k+m==n) printf("%lld\n",m*m*k); else printf("-1\n"); } } return 0; }
Triangle Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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 yi (−109≤xi,yi≤109).
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
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #pragma GCC diagnostic error "-std=c++11" #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define esp 1e-9 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;} typedef long long ll; struct node { int x,y,z; bool operator<(const node &a)const{ return a.x==x?a.y>y:a.x>x; } }e[10006]; int n,t; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<3*n;i++) { scanf("%d%d",&e[i].x,&e[i].y); e[i].z=i+1; } sort(e,e+3*n); for(int i=0;i<3*n;i++) { if(i%3==2) printf("%d\n",e[i].z); else printf("%d ",e[i].z); } } return 0; }
Distinct Values
Problem Description
Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (l≤i<j≤r), ai≠aj holds.
Chiaki would like to find a lexicographically minimal array which meets the facts.
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 two integers n and m (1≤n,m≤105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.
Output
For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.
Sample Input
3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
Sample Output
1 2
1 2 1 2
1 2 3 1 1
区间排序,求最长区间
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #pragma GCC diagnostic error "-std=c++11" #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define esp 1e-9 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;} typedef long long ll; int n,m,t,ans[100006]; struct node { int l,r,id; friend bool operator <(node a,node b) { return a.l==b.l?a.r>b.r:a.l<b.l; } }q[100006]; set<int>s; int main() { scanf("%d",&t); while(t--) { s.clear(); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) s.insert(i); for(int i=1;i<=m;i++) scanf("%d%d", &q[i].l, &q[i].r); sort(q+1, q+m+1); int r=0,l=1; for(int i=1;i<=m;i++) { if(q[i].r <= r) continue; if(q[i].l > r) { while(r<q[i].l) ans[++r]=1; while(l<q[i].l) s.insert(ans[l++]); if((*s.begin())==1) s.erase(s.begin()); while(r<q[i].r) { ans[++r]=(*s.begin()); s.erase(s.begin()); } } else if(q[i].l<=r) { while(l<q[i].l) s.insert(ans[l++]); while(r<q[i].r) { ans[++r]=(*s.begin()); s.erase(s.begin()); } } } while(r<n) ans[++r]=1; for(int i=1;i<=n;i++) printf("%d%c", ans[i], i==n?'\n':' '); } return 0; }
Time Zone
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.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), 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,X.Y≤14,0≤Y≤9).
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
注意上溢和下溢
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #pragma GCC diagnostic error "-std=c++11" #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define esp 1e-9 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) (memset(a,0,sizeof(a))) int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;} typedef long long ll; int a,b,n,m; char s[25]; int t; int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); n=(n+16)%24; scanf("%s",s); bool flag=0; a=0,b=0; for(int i=4;s[i];i++) { if(s[i]=='.'){flag=1;continue;} if(!flag) a=a*10+(int)(s[i]-'0'); else b=b*10+(int)(s[i]-'0'); } b=b*6; if(s[3]=='+') { m+=b; if(m>=60){ m%=60; n++; } n+=a; n%=24; } else { m-=b; if(m<0){ m+=60; n--; } n-=a; n=(n+24)%24; } printf("%02d:%02d\n",n,m); } return 0; }