Codeforces Round #470 Div. 1
A:暴力枚举x2的因子,由此暴力枚举x1,显然此时减去其最大质因子并+1即为最小x0。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 1000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,p[N],prime[N],cnt,ans=N;
bool flag[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
flag[1]=1;
for (int i=2;i<=1000000;i++)
{
if (!flag[i]) {prime[++cnt]=i;p[i]=i;}
for (int j=1;j<=cnt&&prime[j]*i<=n;j++)
{
flag[prime[j]*i]=1;
p[prime[j]*i]=p[i];
if (i%prime[j]==0) break;
}
}
for (int i=1;i<=n;i++)
if (n%i==0&&!flag[i])
{
for (int x=n-i+1;x<=n;x++)
if (flag[x]) ans=min(ans,x-p[x]+1);
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
B:小根堆维护每堆雪的体积,记录总偏移量,堆顶融化完就将其弹出。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define int long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],b[N],cnt;
priority_queue<int,vector<int>,greater<int> > q;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) b[i]=read();
ll delta=0;
for (int i=1;i<=n;i++)
{
q.push(a[i]+delta);cnt++;ll ans=0;
while (!q.empty()&&q.top()<=b[i]+delta) ans+=q.top()-delta,cnt--,q.pop();
ans+=1ll*b[i]*cnt;delta+=b[i];
printf("%I64d ",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}
C:建棵trie,维护子树内数的个数,暴力按位贪心即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],b[N],trie[N<<5][2],size[N<<5],cnt;
void ins(int x)
{
int k=0;
for (int i=31;~i;i--)
{
if (!trie[k][(x&(1<<i))>0]) trie[k][(x&(1<<i))>0]=++cnt;
k=trie[k][(x&(1<<i))>0];
size[k]++;
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) ins(read());
for (int i=1;i<=n;i++)
{
int k=0,x=0;
for (int j=31;~j;j--)
{
if (a[i]&(1<<j))
{
if (size[trie[k][1]]) k=trie[k][1];
else k=trie[k][0],x|=(1<<j);
}
else
{
if (size[trie[k][0]]) k=trie[k][0];
else k=trie[k][1],x|=(1<<j);
}
size[k]--;
}
printf("%d ",x);
}
return 0;
//NOTICE LONG LONG!!!!!
}
D:降智好题。首先发现BC可以相互转化,变换3次再删掉AAA即可。同时发现每次可以增加AA,由于可以删除AAA,也就是说可以任意增删AA。并且BC的数量不会减少且奇偶性不变。哇这个题好弱智!一发wa on 2。
冷静一下可以发现,当原串没有BC且目标串也没有BC时,我们是不能任意变换的,而只能删除AAA。于是特判一下这种情况。哇这个题好弱智!一发wa on 8。
再冷静一下发现,我们对A的增删事实上并不能在尾部进行。于是满足之前条件的同时,数一下原串尾部A的长度x和目标串尾部A的长度y。如果BC数量相同,只能通过删AAA来对尾部变换,于是判一下是否x%3==y%3&&x>=y;否则可以在任意位置截掉,只需要x>=y。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
char a[N],b[N];
int n,m,q,s1[N],s2[N];
int query1(int x,int y)
{
int l=x,r=y+1,ans=y+1;
while (l<=r)
{
int mid=l+r>>1;
if (s1[mid]==s1[y]) ans=mid,r=mid-1;
else l=mid+1;
}
return y-ans+1;
}
int query2(int x,int y)
{
int l=x,r=y+1,ans=y+1;
while (l<=r)
{
int mid=l+r>>1;
if (s2[mid]==s2[y]) ans=mid,r=mid-1;
else l=mid+1;
}
return y-ans+1;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
scanf("%s",a+1);n=strlen(a+1);
scanf("%s",b+1);m=strlen(b+1);
for (int i=1;i<=n;i++) s1[i]=s1[i-1]+(a[i]!='A');
for (int i=1;i<=m;i++) s2[i]=s2[i-1]+(b[i]!='A');
q=read();
while (q--)
{
int l1=read(),r1=read(),l2=read(),r2=read();
int x=s1[r1]-s1[l1-1],y=s2[r2]-s2[l2-1];
if (x|y)
{
int u=query1(l1,r1),v=query2(l2,r2);
if (x==y)
{
if (u%3==v%3&&u>=v) putchar('1');
else putchar('0');
}
else if (x>y) putchar('0');
else
{
if ((x&1)==(y&1)&&u>=v) putchar('1');
else putchar('0');
}
}
else
{
if ((r1-l1)%3==(r2-l2)%3&&(r1-l1>=r2-l2)) putchar('1');
else putchar('0');
}
}
return 0;
//NOTICE LONG LONG!!!!!
}
E怎么是这种不可能会的板子题啊
Codeforces Round #470 Div. 1的更多相关文章
- 【二分】Producing Snow @Codeforces Round #470 Div.2 C
time limit per test: 1 second memory limit per test: 256 megabytes Alice likes snow a lot! Unfortuna ...
- Codeforces Round #470 Div. 2题解
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #470 (Div. 2) A Protect Sheep (基础)输入输出的警示、边界处理
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to w ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- ASP.NET Core MVC之ViewComponents(视图组件)知多少?
前言 大概一个来星期未更新博客了,久违了各位,关于SQL Server性能优化会和ASP.NET Core MVC穿插来讲,如果你希望我分享哪些内容可以在评论下方提出来,我会筛选并看看技术文档来对你的 ...
- babel-polyfill使用与性能优化
文章首发于笔者的个人博客 文章概览 本文主要内容包括:什么是babel-polyfill,如何使用,如何通过按需加载进行性能优化. 本文所有例子可以在 笔者的github 找到. 什么是babel-p ...
- UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- CodeForces - 1051D-简单DP
这个题叫问给一个2*N的方块,你可以在每一个上填任意黑或者白两种,假设颜色相同的并且有公共边的就被认为是一块,问组成K块有多少种方案. 这题开始感觉无从下手,像组合数学又不像的,其实这个题的关键在于, ...
- iOS数据存储-钥匙串存储
2017.11.20 14:41* 字数 227 阅读 678评论 0喜欢 0 钥匙串介绍 1. 表示设备唯一号的标识,在IOS7中要么被禁止使用,要么重新安装程序后两次获取的标识符不一样. 2. ...
- stark组件配置,二层URL
1.django的admin配置 2 stark组件开发 3.2层url分发 4.小结 1.django的admin配置 model.py from django.db import models # ...
- 【kindle笔记】之 《黑客微百科》-2018-6-17
前段时间复习六级的时候,从图书馆看到一本书,然后带回来了.今天开始读.今天是2018年6月17日. 严格来讲,一本不算kindle笔记的笔记,不过广义的啃豆笔记了解一下.哈哈. 首页说到的黑客理念是: ...
- npm5踩过的坑!
1. 版本问题导致环境问题 我们第一次npm install时是根据package.json来安装相关依赖的,但是它里面的版本不固定,因此默认会根据最高的版本来安装相关依赖,但是在npm5是根据pac ...
- [转帖] SS, SP, BP 三个寄存器
SS, SP, BP 三个寄存器 https://blog.csdn.net/vspiders/article/details/55669265 这么看 计算机组成原理 还有 考试的很多题目非常有用啊 ...
- 【转帖】理解 Linux 的虚拟内存
理解 Linux 的虚拟内存 https://www.cnblogs.com/zhenbianshu/p/10300769.html 段页式内存 文章了里面讲了 页表 没讲段表 记得最开始的时候 学习 ...