预计分数: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.......

 include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
const LL MAXN=1e6+;
inline LL read()
{
char c=getchar();LL flag=,x=;
while(c<''||c>'') {if(c=='-') flag=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-,c=getchar();return x*flag;
}
LL n;
LL fastpow(LL a,LL p)
{
LL base=;
while(p)
{
if(p&) base=base*a;
a=a*a;
p>>=;
}
return base;
}
LL pow3[MAXN];
struct node
{
LL val;
LL pos;
bool flag;
node() { val=pos=flag=; }
}qus[];
LL tot=;
LL comp(const node &a,const node &b)
{
return a.val<b.val;
}
LL comp2(const node &a,const node &b)
{
return a.pos<b.pos;
}
int main()
{
//freopen("cubic.in","r",stdin);
//freopen("cubic.out","w",stdout);
for(LL i=;i<=1e6+;i++)
pow3[i]=fastpow(i,);
LL n=read();
while(n--)
{
qus[++tot].val=read();
qus[tot].pos=tot;
}
sort(qus+,qus+tot+,comp);
LL now=;//处理到第几个
for(LL i=;i<=1e6+;i++)
{
while(pow3[i]>qus[now].val&&now<=tot) now++;
while(pow3[i]==qus[now].val&&now<=tot) qus[now].flag=,now++;
}
sort(qus+,qus+tot+,comp2);
for(LL i=;i<=tot;i++)
{
if(qus[i].flag==) printf("NO\n");
else printf("YES\n");
}
return ;
}
 #include <bits/stdc++.h>
using namespace std;
long long A;
int T;
bool work(long long x)
{
for (int i=; ; i++)
{
if (1ll*i*i*i==x) return true;
if (1ll*i*i*i>x) return false;
}
}
int main()
{
freopen("cubic.in","r",stdin);
freopen("cubic.out","w",stdout);
scanf("%d",&T);
while (T--)
{
scanf("%I64d",&A);
if (work(A)) puts("YES"); else puts("NO");
}
return ;
}

标程

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就好

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define LL long long
using namespace std;
inline int read()
{
char c=getchar();int flag=,x=;
while(c<''||c>'') {if(c=='-') flag=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-,c=getchar();return x*flag;
}
int main()
{
int n=read();
while(n--)
{
int p=read();bool flag=;
for(int i=;i<=1e6;i++)
{
if(*i*i-*i+==p)
{
flag=;
break;
}
}
if(flag==) printf("NO\n");
else printf("YES\n");
}
return ;
}

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))$

 #include <cstdio>
#include <iostream>
#include <algorithm>
#define N 1000011
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
using namespace std;
int n, q, ans;
int f[N]; struct node
{
int x, y, z;
}p[N], t[N]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline bool cmp(node x, node y)
{
return x.z > y.z;
} inline int find(int x)
{
return x == f[x] ? x : f[x] = find(f[x]);
} inline bool check(int k)
{
int i, j, x, y, lmin, lmax, rmin, rmax;
for(i = ; i <= n + ; i++) f[i] = i;
for(i = ; i <= k; i++) t[i] = p[i];
std::sort(t + , t + k + , cmp);
lmin = lmax = t[].x;
rmin = rmax = t[].y;
for(i = ; i <= k; i++)
{
if(t[i].z < t[i - ].z)
{
if(find(lmax) > rmin) return ;
for(j = find(lmin); j <= rmax; j++)
f[find(j)] = find(rmax + );
lmin = lmax = t[i].x;
rmin = rmax = t[i].y;
}
else
{
lmin = min(lmin, t[i].x);
lmax = max(lmax, t[i].x);
rmin = min(rmin, t[i].y);
rmax = max(rmax, t[i].y);
if(lmax > rmin) return ;
}
}
// cout<<find(1)<<endl;
if(find(lmax) > rmin) return ;
return ;
} int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
int i, x, y, mid;
n = read();
q = read();
for(i = ; i <= q; i++)
p[i].x = read(), p[i].y = read(), p[i].z = read();
x = , y = q;
//cout<<check(2)<<endl;
//return 0;
ans = q + ;
while(x <= y)
{
mid = (x + y) >> ;
if(check(mid)) ans = mid, y = mid - ;
else x = mid + ;
}
printf("%d\n", ans);
return ;
}

没时间写了贴个标程

总结

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

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

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

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

												

最新文章

  1. ASP.NET MVC 5 - 验证编辑方法(Edit method)和编辑视图(Edit view)
  2. 蚂蚁金服寒泉子:JVM源码分析之临门一脚的OutOfMemoryError完全解读
  3. PostgreSQL Hot Standby的主备切换
  4. CSS第四天总结 更多的属性 圆角 边框图片 段落属性 颜色渐变 盒子阴影
  5. Redis 数据库
  6. ios 动态测定字符串frame : boundingRectWithSize函数
  7. JAVA题目
  8. ImportError: No module named &#39;commands&#39;
  9. .net 实现 URL重写,伪静态(方法一)
  10. C# 循环获取目录
  11. iptables 问题
  12. LeetCode OJ 169. Majority Element
  13. EM and GMM(Code)
  14. 《Node.js在CLI下的工程化体系实践》成都OSC源创汇分享总结
  15. ubuntu中安装ftp服务器
  16. SQL注入: with rollup特性
  17. Linux下查看设设置时间date命令
  18. python heapq模块使用
  19. 深入 Nginx 之配置篇
  20. javascript奇技淫巧之位运算符

热门文章

  1. c# protected public private internal
  2. NetBios, NetBios over TCP/IP, SMB 之间的关系
  3. 通过.ENV文件来配置ThinkPHP的数据库连接信息
  4. [洛谷P1156][codevs1684]垃圾陷阱
  5. who---显示目前登录系统的用户信息
  6. 杭电 HDU ACM 2795 Billboard(线段树伪装版)
  7. 伸缩--也可用于tabs
  8. js实现小时钟,js中Date对象的使用?
  9. 在VPS上用Outline Manager 建立*** 增强版服务器
  10. Mybatis传多个参数(推荐)