Codeforces Round #553 (Div. 2) 题解
昨晚深夜修仙上紫记,虽然不错还是很有遗憾的。
A. Maxim and Biology
看完就会做的题,然而手速跟不上
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=; char ss[]; int a[];
int getdis(int x,int y)
{
if(x>y)swap(x,y);
return min(y-x,x+-y);
}
int main()
{
int n,m;
scanf("%d%s",&n,ss+);
for(int i=;i<=n;i++)a[i]=ss[i]-'A'+; int mn=(<<);
for(int i=;i<=n-;i++)
{
mn=min(mn,getdis(a[i],)+getdis(a[i+],)+getdis(a[i+],)+getdis(a[i+],));
}
printf("%d\n",mn); return ;
}
A. Maxim and Biology
B. Dima and a Bad XOR
其实先开的是B,但是O(nm*1024)相当不靠谱不是很敢写。。。后来写得还是磕磕绊绊总之相当不爽。就是那种要抢时间这个题又烦的一批的感觉
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=; int a[maxn][maxn];
bool f[maxn][];int d[maxn][],fr[maxn][]; int as[maxn];
int main()
{
int n,m,mx=;
scanf("%d%d",&n,&m);
f[][]=true;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]),mx=max(mx,a[i][j]); while(mx!=(mx&-mx))mx-=(mx&-mx);
mx<<=;
if(mx==)mx=; for(int i=;i<n;i++)
for(int zt=;zt<mx;zt++)
if(f[i][zt])
{
for(int j=;j<=m;j++)
f[i+][zt^a[i+][j]]=true,d[i+][zt^a[i+][j]]=j,fr[i+][zt^a[i+][j]]=zt;
} for(int zt=;zt<mx;zt++)
if(f[n][zt])
{
puts("TAK");
for(int i=n;i>=;i--)
{
as[i]=d[i][zt],zt=fr[i][zt];
}
for(int i=;i<=n;i++)printf("%d ",as[i]);
puts("");return ;
}
puts("NIE"); return ;
}
B. Dima and a Bad XOR
C. Problem for Nazar
和B一起让我自闭了半个多小时,看错一发题意。其实就是按题意模拟,然后写到45min才过真是!@#¥%……&,也是疯狂调试没什么底的,还好样例比较强。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL mod=1e9+;
inline LL ad(LL x,LL y){return (x>=mod-y)?(x-mod+y):x+y;}
inline LL re(LL x,LL y){return (x<y)?(x-y+mod):x-y;} LL solve(LL n)
{
if(n==)return ;
int op=; LL i,step=,ost=,est=,ret=;
for(i=;i<=n;i<<=)
{
if(step+i>=n)break;
if(op==)
{
LL ed=ost+*(i-);
ret=ad(ret,(ost+ed)%mod*(i%mod)%mod*(mod/+)%mod);
ost=ed+;
}
else
{
LL ed=est+*(i-);
ret=ad(ret,(est+ed)%mod*(i%mod)%mod*(mod/+)%mod);
est=ed+;
}
op^=;
step+=i;
}
if(op==)
{
LL ed=ost+*(n-step-);if(ed%==)ed--;
ret=ad(ret,(ost+ed)%mod*((n-step)%mod)%mod*(mod/+)%mod);
}
else
{
LL ed=est+*(n-step-);if(ed%==)ed--;
ret=ad(ret,(est+ed)%mod*((n-step)%mod)%mod*(mod/+)%mod);
} return ret;
} int main()
{
LL l,r;
scanf("%lld%lld",&l,&r);
printf("%lld\n",re(solve(r),solve(l-))); return ;
}
C. Problem for Nazar
D. Stas and the Queue at the Buffet
sb微扰。我觉得比A还sb。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=1e5+_; struct node{int a,b;}p[maxn];
bool cmp(node n1,node n2){return n1.a-n1.b>n2.a-n2.b;}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&p[i].a,&p[i].b);
sort(p+,p+n+,cmp); LL ans=;
for(int i=;i<=n;i++)
{
ans+=(LL)(i-)*p[i].a+(LL)(n-i)*p[i].b;
}
printf("%lld\n",ans); return ;
}
D. Stas and the Queue at the Buffet
E. Number of Components
这个E岂不是搞笑的??明明O(n)还放1e5
考虑已经得到前i-1个点的贡献,现在加入i这个点,假如a[i]不在[l,r]里面或a[i],a[i-1]都在[l,r]里面它没有贡献,否则就会产生贡献。
第二天rose_king又给出了一个更直观的做法:因为联通块数=总点数-被删的边数,答案就是=总点数-被删的边数-不在[l,r]的点数
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=1e5+_; int a[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]); LL ans=(LL)(a[]-)*(n-a[])+n; int L,R;
for(int i=;i<=n;i++)
{
if(a[i]==a[i-])continue;
if(a[i]>a[i-])
{
L=a[i]--a[i-],R=n-a[i];
}
else if(a[i]<a[i-])
{
L=a[i]-,R=a[i-]--a[i];
}
ans+=(LL)L*R+L+R+;
}
printf("%lld\n",ans); return ;
}
E. Number of Components
F. Sonya and Informatics
这个F也是我有问题,看错了一发题意浪费了半个小时,然后脑子不清醒写了个假的,其实只要设f[i]表示在正确位置的1的个数为i然后明显矩乘优化就完事了
咕了
这几场手速都是极大的劣势
天天又看错题
还很慢热,写完模拟才有点做题的感觉
总之就是菜鸡一个
不过没fail题算是有点安慰吧
Codeforces Round #553 (Div. 2) 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*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) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
随机推荐
- Failed to read artifact descriptor for avalon-framework:avalon-framewor
在工程中,遇到了这个问题,百度了好久并没有满意的解决方案. 网上有一种办法是: 一.修改.m2/repository/avalon-framework/avalon-framework-api/里所有 ...
- ID3算法Java实现
ID3算法java实现 1 ID3算法概述 1.1 信息熵 熵是无序性(或不确定性)的度量指标.假如事件A的全概率划分是(A1,A2,...,An),每部分发生的概率是(p1,p2,...,pn).那 ...
- 如何在VS2010中添加ActiveX控件及使用方法
方法1: 1.首先在在项目上面右击添加类,如下图所示: 2.点击添加ActiveX控件中的MFC类 3.找到需要添加的ActiveX类. 4.点击完成即可. 5.此时转到资源视图,打开如下视图.可能工 ...
- Robot Framework使用Phantomjs进行无界面UI自动化测试
Robot Framework 是一款关键字驱动的验收自动化测试框架,现在在国内使用的越来越广泛了.一种通用的Web UI自动化测试解决方案是Robot Framework+Selenium2Libr ...
- 【Android应用开发详解】实现第三方授权登录、分享以及获取用户资料
由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折,查阅了一番资料,做了一个Demo.实现起来的效果还是不错的,不敢独享,决定写一个总结的教程,供大家互相 ...
- 开发ActiveX控件调用另一个ActiveX系列1——开发一个MFC ActiveX控件
ActiveX开发的教程有很多,我也从中受益匪浅,例如以下这几篇: 基本教程:http://www.cnblogs.com/guenli/articles/1629915.html 注意事项:http ...
- android开发系列之使用xml自定义控件
在android开发的过程中,有的时候面对多个Activity里面一些相同的布局,我们需要写多次相同的代码,同时这种方法给我们的项目维护也带来了很大不便.那么有没有一种可行的办法能够将Activity ...
- caffe2--------ImportError: No module named past.builtins
whale@sea:~/anaconda2/lib/python2.7/site-packages$ python Python 2.7.14 |Anaconda custom (64-bit)| ( ...
- MySQL联表更新插入数据
Error: DELETE FROM t_23andme_addref WHERE id IN ( SELECT min(id) FROM t_23andme_addref GROUP BY ...
- 有关Cache –(1) linux list之中的Prefetc
转载:http://www.kernelchina.org/node/1050 linux的list实现之中有如下东东: #define list_for_each(pos, head) \ ...