2018暑期多校1
阿新 • • 發佈:2018-07-23
test sca separate efi array ram and class multiple
The first line contains an integer n (1≤n≤106).
Chiaki would like to find a lexicographically minimal array which meets the facts.
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.
1001
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: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 3Sample Output
-1 -1 11 #include <bits/stdc++.h> 2 using namespaceView Codestd; 3 int main() 4 { 5 int T; 6 scanf("%d",&T); 7 while (T--) 8 { 9 long long n; 10 scanf("%lld",&n); 11 if(n%3==0) 12 { 13 printf("%lld\n",(n/3)*(n/3)*(n/3)); 14 } else if(n%4==0) 15 { 16 printf("%lld\n",(n/2)*(n/4)*(n/4)); 17 } 18 else printf("-1\n"); 19 20 21 } 22 return 0; 23 }
HDU 6301
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≠ajholds.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題解:
先對給定的區間排序,然後每次講前一個比後一個區間多出的部分加入優先對列,找到最小的然後放到ans數組。這個代碼有點卡時間,
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 5 const int MAXN = 1e5+10; 6 7 8 int t,n,m; 9 10 int ans[MAXN]; 11 struct node{ 12 int l,r; 13 }p[MAXN],pre; 14 struct CMP{ 15 bool operator ()(int a,int b){ 16 return a > b; 17 } 18 }; 19 bool cmp(node a,node b){ 20 if(a.l!=b.l) return a.l < b.l; 21 else return a.r > b.r; 22 } 23 24 int main(){ 25 scanf("%d",&t); 26 while(t--){ 27 memset(ans,0,sizeof(ans)); 28 memset(p,0,sizeof(p)); 29 scanf("%d%d",&n,&m); 30 priority_queue<int, vector<int>,CMP>Q; 31 for(int i=0;i<m;i++){ 32 scanf("%d%d",&p[i].l,&p[i].r); 33 } 34 sort(p,p+m,cmp); 35 int maxx = 1; 36 pre.l = p[0].l; 37 pre.r = p[0].r; 38 for(int i=1;i<=p[0].r-p[0].l+1;i++){ 39 ans[p[0].l+i-1] = i; 40 maxx = max(maxx,i); 41 } 42 for(int i=1;i<m;i++){ 43 if(p[i].r <= pre.r) continue; 44 else { 45 for(int j=pre.l;j<min(p[i].l,pre.r+1);j++){ 46 Q.push(ans[j]); 47 } 48 int temp =max(pre.r+1,p[i].l); 49 while(!Q.empty()&&temp<=p[i].r){ 50 ans[temp++]=Q.top(); 51 Q.pop(); 52 } 53 if(temp<=p[i].r){ 54 for(int k=temp;k<=p[i].r;k++){ 55 ans[k]=++maxx; 56 } 57 } 58 } 59 pre.l=p[i].l; 60 pre.r=p[i].r; 61 } 62 for(int i=1;i<=n;i++){ 63 if(ans[i]==0)ans[i]=1; 64 } 65 for(int i=1;i<n;i++){ 66 printf("%d ",ans[i]); 67 }printf("%d\n",ans[n]); 68 } 69 return 0; 70 }View Code
2018暑期多校1