2020杭电多校第八场部分题解(1003/1006/1008)

1003

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6857

Problem Description
It is preferrable to read the pdf statment.
After some basic geometric lessons, Cuber QQ has learned that one can draw one and only one circle across three given distinct points, on a 2D plane. Specialized in art, Cuber QQ has shown remarkable skills to draw circle in one stroke, especially when the stroke is done clockwise. He wonder whether he will be able to do that if 3 points has been given.
In particular, he is given three distinct points A(x1,y1) , B(x2,y2) , C(x3,y3) which lie on a circle centered at O(0,0) . Imagine starting from A , he draws the circle across B and finally gets C . Determine whether he is drawing clockwise or counterclockwise.
 
Input
The first line contains an integer T (1T1 000 ), denoting the number of test cases.
In the next T lines, each line contains six space-separated integers x1 , y1 , x2 , y2 , x3 , y3 (109x1,y1,x2,y2,x3,y3109 ) denoting the coordinate of A , B and C .
It is guaranteed that A, B, Care pairwise distinct and |AO|=|BO|=|CO|>0 .
 
Output
For each test case, output one line containing ''Clockwise'' or ''Counterclockwise''.
 
Sample Input
3
1 2 2 1 -1 -2
4 3 -4 3 3 4
4 -3 4 3 3 4
 
Sample Output
Clockwise
Clockwise
Counterclockwise
题解:水题,先求向量,再用差积
代码:
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+5;
int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--){
        int x1,x2,x3,y1,y2,y3;
        scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
        int px1=x2-x1,py1=y2-y1;
        int px2=x3-x2,py2=y3-y2;
        ll ans=1LL*px1*py2-1LL*py1*px2;
        if(ans>0)printf("Counterclockwise\n");
        else printf("Clockwise\n");
    }
    return 0;
}
1003

 

1006

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6857

Problem Description
It is preferrable to read the pdf statment.

Cuber QQ has signed up for a gambling game, that challenges him to predict the stock price of Quber CC Limited, for the next following n days. He shall make his prediction by filling a table with intervals,
the i -th of which is the predicted interval [li,ri] at the i -th day. If all n prices lie in the corresponding interval, Cuber QQ will win 1 million dollars. Otherwise, he will not earn a single penny.
As is well known, the stock price has a fluctuation limit. For simplicity, we assume the limit up and the limit down are both k , which is an integer. That means, if the stock price at the i -th day is x , the price at the i+1 -th day is at most x+k and at least xk .
Cuber QQ wants to know whether it is possible to manipulate the stock price, without breaking the limitation above of course, so that he can have the 1 million dollars. Since his table has already been submitted,
he cannot modify his predicted intervals any more. It has to be done secretly behind the scenes, and smartly cover it up so that no one will notice.
 
Input
The input starts with an integer T (1T105 ), denoting the number of test cases.
For each test case, the first line contains two space-separated integers n and k (2n105 , 0k109 ), where n is the number of days and k is the fluctuation limit.
The i -th line of the next n lines contains two space-separated integers li and ri (0liri109 ), which is Cuber QQ's predicted interval in the i -th day. A prediction is believed to be correct if the stock price i -th day lies between li and ri , inclusive.
It is guaranteed that the sum of all n does not exceed 106 .
 
Output
For each test case, first output a single line YES or NO, that states whether Cuber QQ will win the 1 million price.
If YES, in the next line, output a possible price series, a1,a2,,an , where liairi (1in ) and |aiai+1|k (1in1 ). The integers should be separated with space.
 
Sample Input
2
3 1
1 6
2 5
3 6
2 3
1 5
10 50
 
Sample Output
YES
2 3 3
NO
题解:如果 i 是在 [l, r] 范围内, 那么 i + 1 必须要在 [ll k, r + k] 范围内.这是因为如果 i + 1 选了范围外的值, i 就无解了,
这样可以从左往右, 把左边的约束带到右边.再从右往左做一遍.最后剩下的区间应该就是可行域.因为题目只要求一种方案, 全部选最低的即可
代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef unsigned long long ull;
 5 const int N=1e5+5;
 6 ll l[N],r[N],ans[N],ll1[N],rr[N];
 7 int main()
 8 {
 9     int T,n,i;
10     scanf("%d",&T);
11     while(T--){
12         int n,k;
13         scanf("%d%d",&n,&k);
14         for(i=1;i<=n;i++){
15             scanf("%lld%lld",&l[i],&r[i]);
16         }
17         int f=1;
18         ll1[1]=l[1],rr[1]=r[1];
19         for(i=2;i<=n;i++){
20             ll al=ll1[i-1]-k,ar=rr[i-1]+k;//allow
21             ll1[i]=max(al,l[i]);
22             rr[i]=min(ar,r[i]);
23             if(ll1[i]>rr[i]){
24                 f=0;
25                 break;
26             }
27         }
28         if(f==0)printf("NO");
29         else{
30             printf("YES\n");
31             ans[n]=ll1[n];
32             for(i=n-1;i>=1;i--){
33                 ll al=ans[i+1]-k,ar=ans[i+1]+k;//allow
34                 ans[i]=max(al,ll1[i]);
35             }
36             for(i=1;i<=n;i++){
37                 if(i!=1)printf(" ");
38                 printf("%lld",ans[i]);
39             }
40         }
41         printf("\n");
42     }
43     return 0;
44 }
1006

 

1008

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6857

Problem Description

It is preferrable to read the pdf statment.
If the world is a hexagon, I will take as many turns as possible before reaching the end.
Cuber QQ has constructed a hexagon grid with radius n . This will be better if explained in a picture. For example, this is a hexagon grid with radius 3 :



He challenges you take a perfect tour over the hexagon, that is to visit each cell exactly once. Starting from any point in the grid, you can move to any adjacent cell in each step. There are six different directions you can choose from:



Of course, if you are on the boundary, you cannot move outside of the hexagon.
Let D(x,y) denote the direction from cell x to y , and sequence A denotes your route, in which Ai denotes the i -th cell you visit. For index i (1<i<|A| ), if D(Ai1,Ai)D(Ai,Ai+1) , we say there is a turning on cell i .
Maximize the number of turning while ensuring that each cell is visited exactly once. Print your route. If there are multiple solution, print any.
 
Input
The first line of the input contains a single integer T (1T104 ), denoting the number of test cases.
Each of the next T cases:
The first line contains an integer n (2n500 ).
It is guaranteed that the sum of n doesn't exceed 2104 .
 
Output
For each test case, output one line contains a string with 3(n1)n characters. The i -th character is D(Ai,Ai+1) .
 
Sample Input
1 2
 
Sample Output
313456
题解:
 
代码:
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N = 1e3+5;
 4 int flag;
 5 void dfs(int n)
 6 {
 7     if(n==0) return;
 8     if(n==1){
 9         printf("4");
10         return;
11     }
12     if(flag) printf("4");
13     flag++;
14     printf("3");
15     for(int i=1;i<=n-2;i++) printf("42");
16     printf("4");
17     for(int i=1;i<=n-2;i++) printf("53");
18     printf("5");
19     for(int i=1;i<=n-2;i++) printf("64");
20     printf("6");
21     for(int i=1;i<=n-2;i++) printf("15");
22     printf("1");
23     for(int i=1;i<=n-2;i++) printf("26");
24     if(n>=3){
25         printf("2");
26         for(int i=1;i<=n-3;i++)printf("31");
27     }
28     printf("3");
29     dfs(n-2);
30 }
31 int main()
32 {
33     int t,n;
34     scanf("%d",&t);
35     while(t--)
36     {
37         flag=0;
38         scanf("%d",&n);dfs(n);
39         cout<<endl;
40     }
41 }
1008

 

posted @ 2020-08-13 20:24  麦客_zeng  阅读(289)  评论(0)    收藏  举报