Day1上午解题报告

时间:2022-05-08
本文章向大家介绍Day1上午解题报告,主要内容包括预计分数:100+60+0=160、实际分数:100+30+20=150、T1立方数(cubic)、输入输出格式、输入输出样例、说明、T2立方数2(cubicp)、输入输出格式、输入输出样例、说明、T3上午猜数字(number)、输入输出格式、输入输出样例、说明、总结、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

预计分数:100+60+0=160

实际分数:100+30+20=150

T1立方数(cubic)

题目描述

LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数。

现在给定一个数P,LYK想要知道这个数是不是立方数。

当然你有可能随机输出一些莫名其妙的东西来骗分,因此LYK有T次询问~

输入输出格式

输入格式:

第一行一个数T,表示有T组数据。

接下来T行,每行一个数P。

输出格式:

输出T行,对于每个数如果是立方数,输出“YES”,否则输出“NO”。

输入输出样例

输入样例#1:

3
8
27
28

输出样例#1: 

YES
YES
NO

说明

对于30%的数据p<=100。

对于60%的数据p<=10^6。

对于100%的数据p<=10^18,T<=100。

这题做的我心累啊,,

我一看数据范围p<=1e18,也就是我们需要枚举到1e6,100组询问,最坏情况的话会T

此时我机(sha)智(bi)的把每次询问做离线处理

按照询问的权值排序,用双指针法,依次判断,

然后把询问按照入读的顺序排序,输出就好

不过,事实证明,

zhw没这么毒瘤,直接依次枚举就能A了。。。。。。。。。

看到标程的我眼泪流下来啊QWQ.......

 1 include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #define LL long long 
 7 using namespace std;
 8 const LL MAXN=1e6+100;
 9 inline LL read()
10 {
11     char c=getchar();LL flag=1,x=0;
12     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
13     while(c>='0'&&c<='9')    x=x*10+c-48,c=getchar();return x*flag;
14 }
15 LL n;
16 LL fastpow(LL a,LL p)
17 {
18     LL base=1;
19     while(p)
20     {
21         if(p&1)    base=base*a;
22         a=a*a;
23         p>>=1;
24     }
25     return base;
26 }
27 LL pow3[MAXN];
28 struct node
29 {
30     LL val;
31     LL pos;
32     bool flag;
33     node()    {    val=pos=flag=0;    }
34 }qus[101];
35 LL tot=0;
36 LL comp(const node &a,const node &b)
37 {
38     return a.val<b.val;
39 }
40 LL comp2(const node &a,const node &b)
41 {
42     return a.pos<b.pos;
43 }
44 int main()
45 {
46     //freopen("cubic.in","r",stdin);
47     //freopen("cubic.out","w",stdout);
48     for(LL i=1;i<=1e6+10;i++)
49         pow3[i]=fastpow(i,3);
50     LL n=read();
51     while(n--)
52     {
53         qus[++tot].val=read();
54         qus[tot].pos=tot;
55     }
56     sort(qus+1,qus+tot+1,comp); 
57     LL now=1;//处理到第几个
58     for(LL i=1;i<=1e6+10;i++)
59     {
60         while(pow3[i]>qus[now].val&&now<=tot)    now++;
61         while(pow3[i]==qus[now].val&&now<=tot)    qus[now].flag=1,now++;
62     } 
63     sort(qus+1,qus+tot+1,comp2);
64     for(LL i=1;i<=tot;i++)
65     {
66         if(qus[i].flag==0)    printf("NOn");
67         else printf("YESn");
68     }
69     return 0;
70 }
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 long long A;
 4 int T;
 5 bool work(long long x)
 6 {
 7     for (int i=1; ; i++)
 8     {
 9         if (1ll*i*i*i==x) return true;
10         if (1ll*i*i*i>x) return false;
11     }
12 }
13 int main()
14 {
15     freopen("cubic.in","r",stdin);
16     freopen("cubic.out","w",stdout);
17     scanf("%d",&T);
18     while (T--)
19     {
20         scanf("%I64d",&A);
21         if (work(A)) puts("YES"); else puts("NO");
22     }
23     return 0;
24 }

T2立方数2(cubicp)

题目描述

LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数。

LYK还定义了一个数叫“立方差数”,若一个数可以被写作是两个立方数的差,则这个数就是“立方差数”,例如7(8-1),26(27-1),19(27-8)都是立方差数。

现在给定一个数P,LYK想要知道这个数是不是立方差数。

当然你有可能随机输出一些莫名其妙的东西,因此LYK有T次询问~

这个问题可能太难了…… 因此LYK规定P是个质数!

输入输出格式

输入格式:

第一行一个数T,表示有T组数据。

接下来T行,每行一个数P。

输出格式:

输出T行,对于每个数如果是立方差数,输出“YES”,否则输出“NO”。

输入输出样例

输入样例#1:

5
2
3
5
7
11

输出样例#1:

NO
NO
NO
YES
NO

说明

对于30%的数据p<=100

对于60%的数据p<=10^6

对于100%的数据p<=10^12,T<=100。

打了个表,结果莫名奇妙少打了一个0

白丢30分。。

正解

x^3-y^3

=(x-y)*(x^2+x*y+y^2)

因为读入的是素数,所以x-y==1

可以得到y=x-1

把y带入

=x^2+x*(x-1)+(x-1)^2

=3*x^2-3*x+1

枚举一个x就好

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<ctime>
 6 #include<cstdlib>
 7 #define LL long long 
 8 using namespace std;
 9 inline int read()
10 {
11     char c=getchar();int flag=1,x=0;
12     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
13     while(c>='0'&&c<='9')    x=x*10+c-48,c=getchar();return x*flag;
14 }
15 int main()
16 {
17     int n=read();
18     while(n--)
19     {
20         int p=read();bool flag=0;
21         for(int i=1;i<=1e6;i++)
22         {
23             if(3*i*i-3*i+1==p)
24             {
25                 flag=1;
26                 break;
27             }
28         }
29         if(flag==0)    printf("NOn");
30         else         printf("YESn");
31     }
32     return 0;
33 }

T3上午猜数字(number)

题目描述

LYK在玩猜数字游戏。

总共有n个互不相同的正整数,LYK每次猜一段区间的最小值。形如[li,ri]这段区间的数字的最小值一定等于xi。

我们总能构造出一种方案使得LYK满意。直到…… LYK自己猜的就是矛盾的!

例如LYK猜[1,3]的最小值是2,[1,4]的最小值是3,这显然就是矛盾的。

你需要告诉LYK,它第几次猜数字开始就已经矛盾了。

输入输出格式

输入格式:

第一行两个数n和T,表示有n个数字,LYK猜了T次。

接下来T行,每行三个数分别表示li,ri和xi。

输出格式:

输出一个数表示第几次开始出现矛盾,如果一直没出现矛盾输出T+1。

输入输出样例

输入样例#1: 

20 4
1 10 7
5 19 7
3 12 8
1 20 1

输出样例#1:

3

说明

对于50%的数据n<=8,T<=10。

对于80%的数据n<=1000,T<=1000。

对于100%的数据1<=n,T<=1000000,1<=li<=ri<=n,1<=xi<=n(但并不保证一开始的所有数都是1~n的)。

Hint 建议使用读入优化

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    return x * f;
}

这题,,我确实逗逼了,,

一开始以为是裸地借教室

结果直到最后5分钟。。

我给自己找了个反例。。。。

GG.....

不过没想到还得了20分,,奇迹啊。。。

正解:

二分答案,有一个显然的结论

两个猜测的最小值如果相同的话那么这个最小值一定在这两个线段的交上

否则,一定在这两个线段的交集关于全集的补集上

当产生冲突的时候一定是权值小的一次猜测被几条比他权值大的猜测完全覆盖,

那么我们可以二分第几次不满足要求,用并查集维护线段的覆盖

时间复杂度:$O(nlgn*α(n))$

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #define N 1000011
 5 #define min(x, y) ((x) < (y) ? (x) : (y))
 6 #define max(x, y) ((x) > (y) ? (x) : (y))
 7 using namespace std;
 8 int n, q, ans;
 9 int f[N];
10 
11 struct node
12 {
13     int x, y, z;
14 }p[N], t[N];
15 
16 inline int read()
17 {
18     int x = 0, f = 1;
19     char ch = getchar();
20     for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
21     for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
22     return x * f;
23 }
24 
25 inline bool cmp(node x, node y)
26 {
27     return x.z > y.z;
28 }
29 
30 inline int find(int x)
31 {
32     return x == f[x] ? x : f[x] = find(f[x]);
33 }
34 
35 inline bool check(int k)
36 {
37     int i, j, x, y, lmin, lmax, rmin, rmax;
38     for(i = 1; i <= n + 1; i++) f[i] = i;
39     for(i = 1; i <= k; i++) t[i] = p[i];
40     std::sort(t + 1, t + k + 1, cmp);
41     lmin = lmax = t[1].x;
42     rmin = rmax = t[1].y;
43     for(i = 2; i <= k; i++)
44     {
45         if(t[i].z < t[i - 1].z)
46         {
47             if(find(lmax) > rmin) return 1;
48             for(j = find(lmin); j <= rmax; j++)
49                 f[find(j)] = find(rmax + 1);
50             lmin = lmax = t[i].x;
51             rmin = rmax = t[i].y;
52         }
53         else
54         {
55             lmin = min(lmin, t[i].x);
56             lmax = max(lmax, t[i].x);
57             rmin = min(rmin, t[i].y);
58             rmax = max(rmax, t[i].y);
59             if(lmax > rmin) return 1;
60         }
61     }
62 //    cout<<find(1)<<endl;
63     if(find(lmax) > rmin) return 1;
64     return 0;
65 }
66 
67 int main()
68 {
69     freopen("number.in","r",stdin);
70     freopen("number.out","w",stdout);
71     int i, x, y, mid;
72     n = read();
73     q = read();
74     for(i = 1; i <= q; i++)
75         p[i].x = read(), p[i].y = read(), p[i].z = read();
76     x = 1, y = q;
77     //cout<<check(2)<<endl;
78     //return 0;
79     ans = q + 1;
80     while(x <= y)
81     {
82         mid = (x + y) >> 1;
83         if(check(mid)) ans = mid, y = mid - 1;
84         else x = mid + 1;
85     }
86     printf("%dn", ans);
87     return 0;
88 }

总结

上午做的太急了,没怎么静下心来思考。

特别是T3,白敲了3k的线段树。。。。

不过,我上午的人品还是不错的

没错我指的是我被zhw rand到了2333333