Codeforces Round #441 Div. 2题解
比赛的时候E调了好久...F没时间写T T
A:直接走到短的路上来回走就好了
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=,inf=1e9;
int n,a,b,c;
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);read(a);read(b);read(c);
if(n==)return puts(""),;
int mn=min(a,min(b,c));int now=;
if(a==mn||b==mn)printf("%d\n",mn*(n-));
else printf("%d\n",min(a,b)+mn*(n-));
}
B:将所有数%m,找到最多的相同的数即可
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=,inf=1e9;
int n,k,m,ans,ansi,cntt;
int x[maxn],y[maxn];
int v[maxn];
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);read(k);read(m);
for(int i=;i<=n;i++)read(x[i]),y[i]=x[i]%m;
for(int i=;i<=n;i++)
{
v[y[i]]++;
if(v[y[i]]>ans)
{
ans=v[y[i]];
ansi=y[i];
}
}
if(ans>=k)
{
puts("Yes");
for(int i=;i<=n;i++)
{
if(y[i]==ansi)printf("%d ",x[i]),cntt++;
if(cntt==k)return ;
}
}
else puts("No");
}
C:答案只可能在[n-100,n]之间,枚举一下就好
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=,inf=1e9;
int n,cnt;
int ans[maxn];
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);
for(int i=max(,n-);i<=n;i++)
{
int x=i,sum=i;
while(x)
{
sum+=x%;
x/=;
}
if(sum==n)ans[++cnt]=i;
}
printf("%d\n",cnt);
for(int i=;i<=cnt;i++)printf("%d ",ans[i]);
}
D:最后连续的硬币删掉,前面还剩多少个硬币就是答案
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=,inf=1e9;
int n,x;
bool b[maxn];
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
puts("");read(n);int N=n;
for(int i=;i<=n;i++)
{
// printf("%dQAQ\n",N);
read(x);b[x]=;
while(b[N])N--;
printf("%d ",i-(n-N)+);
}
}
E:从每种数字可以改或者不改想到2-SAT,如果第i个字符串比第i+1个字符串小,v[i][j]和v[i+1][j]不一样,那么v[i+1][j]改,v[i][j]就必须改,v[i][j]不改,v[i+1][j]就不能改,如果第i个字符串比第i+1个字符串大,那么v[i][j]必须改,v[i+1][j]不能改,如上连边跑一个可行方案即可。
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#define ll long long
using namespace std;
const int maxn=,inf=1e9;
struct poi{int too,pre,x;}e[maxn<<],e2[maxn<<];
int last[maxn],last2[maxn],dfn[maxn],low[maxn],col[maxn],lack[maxn],ru[maxn],rs[maxn],st[maxn],op[maxn];
int n,m,x,y,z,tot,tot2,tott,top,color,flag,len,cnt;
int ans[maxn];
vector<int>v[maxn];
void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
void add(int x,int y){e[++tot].too=y;e[tot].x=x;e[tot].pre=last[x];last[x]=tot;}
void add2(int x,int y){e2[++tot2].too=y;e2[tot2].x=x;e2[tot2].pre=last2[x];last2[x]=tot2;}
int next(int x){return x&?x+:x-;}
void tarjan(int x)
{
dfn[x]=low[x]=++tott;st[++top]=x;lack[x]=top;
for(int i=last[x];i;i=e[i].pre)
if(!dfn[e[i].too])tarjan(e[i].too),low[x]=min(low[x],low[e[i].too]);
else if(!col[e[i].too])low[x]=min(low[x],dfn[e[i].too]);
if(dfn[x]==low[x])for(color++;top>=lack[x];top--)col[st[top]]=color;
}
void topsort()
{
top=;for(int i=;i<=color;i++)if(!ru[i])st[++top]=i;
while(top)
{
int now=st[top--];
if(!rs[now])rs[now]=,rs[op[now]]=;
for(int i=last2[now];i;i=e2[i].pre)
if(!(--ru[e2[i].too]))st[++top]=e2[i].too;
}
}
int main()
{
read(n);read(m);
for(int i=;i<=n;i++)
{
read(len);
for(int j=;j<=len;j++)
read(x),v[i].push_back(x);
}
for(int i=;i<n;i++)
{
int flagg=;
for(int j=;j<min(v[i].size(),v[i+].size());j++)
if(v[i][j]!=v[i+][j])
{
if(v[i][j]<v[i+][j])add(next(v[i+][j]<<),next((v[i][j])<<)),add(v[i][j]<<,v[i+][j]<<);
else add(v[i][j]<<,next((v[i][j])<<)),add(next((v[i+][j])<<),v[i+][j]<<);
flagg=;break;
}
if(!flagg&&v[i].size()>v[i+].size())return puts("No"),;
// else add(next(v[i][min(v[i].size(),v[i+1].size())]<<1),next((v[i+1][min(v[i].size(),v[i+1].size())])<<1));
}
for(int i=;i<=m<<;i++)if(!dfn[i])tarjan(i);
for(int i=;i<=m;i++)
{
if(col[i<<]==col[next(i<<)]){printf("No\n");flag=;break;}
else op[col[i<<]]=col[next(i<<)],op[col[next(i<<)]]=col[i<<];
}
if(flag)return ;
for(int i=;i<=tot;i++)if(col[e[i].x]!=col[e[i].too])add2(col[e[i].too],col[e[i].x]),ru[col[e[i].x]]++;
topsort();
// for(int i=1;i<=tot;i++)printf("QAQ%d %d\n",e[i].x,e[i].too);
//if(rs[col[(i<<1)]]==rs[col[next(i<<1)]])return puts("No"),0;
for(int i=;i<=m;i++)if(rs[col[(i<<)]]!=)ans[++cnt]=i;
printf("Yes\n%d\n",cnt);
for(int i=;i<=cnt;i++)printf("%d ",ans[i]);
return ;
}
F:预处理出每个数每一位是0的那位左边最近的1和右边最近的1,用单调栈找出每个最大值所在的区间,统计答案即可。
T T一开始只预处理了20位查了好久错,浅谈状压写多了的后果
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=,inf=2e9;
int n,top;
int st[maxn],a[maxn],digit[maxn][],pre[maxn][],Pre[maxn],next[maxn][],Next[maxn],cnt[maxn];
ll ans;
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);
for(int i=;i<=n;i++)
{
read(a[i]);
for(int x=a[i];x;x>>=)digit[i][++cnt[i]]=x&;
}
for(int j=,last=;j<=;j++,last=)
for(int i=;i<=n;i++)
{
if(!digit[i][j])pre[i][j]=last;
if(digit[i][j])last=i;
}
for(int i=;i<=n;i++)
for(int j=;j<=;j++)
if(!digit[i][j])
Pre[i]=max(Pre[i],pre[i][j]);
memset(next,,sizeof(next));
for(int j=,last=n+;j<=;j++,last=n+)
for(int i=n;i;i--)
{
if(!digit[i][j])next[i][j]=last;
if(digit[i][j])last=i;
}
memset(Next,,sizeof(Next));
for(int i=;i<=n;i++)
for(int j=;j<=;j++)
if(!digit[i][j])
Next[i]=min(Next[i],next[i][j]);
a[++n]=inf;
for(int i=;i<=n;i++)
{
for(;top&&a[i]>=a[st[top]];top--)
{
ans+=1ll*((i-)-st[top]+)*(st[top]-(st[top-]+)+);
ans-=1ll*(1ll*st[top]-1ll*max(st[top-]+,Pre[st[top]]+)+)*(min(i-,Next[st[top]]-)-st[top]+);
}
st[++top]=i;
}
printf("%lld\n",ans);
}
Codeforces Round #441 Div. 2题解的更多相关文章
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
随机推荐
- 自动化之UI(autoit)
自动化 说到自动化,我真的很不喜欢UI这层去做实践.前置条件要求比较严谨,如果不满足特定的前置条件,那么成本实在太大了. 投入与产出差过大,效果打折扣.从互联网来说,UI自动化是入门门槛很低的一种实践 ...
- PHP精确到毫秒秒杀倒计时实例
精确到毫秒秒杀倒计时PHP源码实例,前台js活动展示倒计时,后台计算倒计时时间.每0.1秒定时刷新活动倒计时时间. PHP: // 注意:php的时间是以秒算.js的时间以毫秒算 // 设置时区 da ...
- spring-boot 项目整合logback
使用spring-boot项目中添加日志输出,java的日志输出一共有两个大的方案log4j/log4j2 ,logback.log4j2算是对log4j的一个升级版本. 常规做法是引入slf4j作为 ...
- 简析Monte Carlo与TD算法的相关问题
Monte Carlo算法是否能够做到一步更新,即在线学习? 答案显然是不能,如果可以的话,TD算法还有何存在的意义?MC算法必须要等到episode结束后才可以进行值估计的主要原因在于对Return ...
- “Hello World!”团队——Final发布用户使用报告
博客内容: 1.用户体验报告表 2.用户评论截图 3.总结 一.用户体验报告表 用户使用报告 用户类别 用户姓名(化名) 性别 用户职业 使用频次 用户评论 新增用户 小小静 女 中学信息技术老师 8 ...
- SSD/Memory技术学习拼图
"打酱油"解读SLC缓存新技术[http://www.pceva.com.cn/article/3612-1.html] 固态硬盘主控将消亡?未来高性能固态硬盘长这样[http:/ ...
- c#程序的阅读
1 .程序是为表示两个连续的整数不能被整除. 2 ,3 程序黑框得不出结果,所以不知道具体的结果和运行时间. 4 采用更好的专用电脑进行计算.
- Java单例模式&static成员变量 区别
当需要共享的变量很多时,使用static变量占用内存的时间过长,在类的整个生命周期. 而对象只是存在于对象的整个生命周期. //饿汉式 class Single//类一加载,对象就已经存在了. { ...
- rfid工作原理
RFID的工作原理是:标签进入磁场后,如果接收到阅读器发出的特殊射频信号,就能凭借感应电流所获得的能量发送出存储在芯片中的产品信息(即Passive Tag,无源标签或被动标签),或者主动发送某一频率 ...
- NLP 入门
作者:微软亚洲研究院链接:https://www.zhihu.com/question/19895141/answer/149475410来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...