2018暑期多校1

Posted -xiangyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018暑期多校1相关的知识,希望对你有一定的参考价值。

1001

Problem Description

Given an integer n, Chiaki would like to find three positive integers xy and z such that: n=x+y+zxnynzn and xyz is maximum.
 

Input

There are multiple test cases. The first line of input contains an integer T (1T106), indicating the number of test cases. For each test case:
The first line contains an integer n (1n106).

 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
技术分享图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 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/3)*(n/3)*(n/3));
14         } else if(n%4==0)
15         {
16             printf("%lld
",(n/2)*(n/4)*(n/4));
17         }
18         else printf("-1
");
19 
20 
21     }
22     return 0;
23 }
View Code

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 (li<jr), aiajholds.
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 (1n,m105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1lirin).

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
",ans[n]);
68     }
69     return 0;
70 }
View Code

 

以上是关于2018暑期多校1的主要内容,如果未能解决你的问题,请参考以下文章

2021牛客暑期多校训练营1 - F - Find 3-friendly Integers - 题解

2021牛客暑期多校训练营1 - F - Find 3-friendly Integers - 题解

2021牛客暑期多校训练营1 - D - Determine the Photo Position - 题解

2021牛客暑期多校训练营1 - A - Alice and Bob - 题解

2021牛客暑期多校训练营1 - A - Alice and Bob - 题解

2021牛客暑期多校训练营2,签到题CDFKI