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 题解 直接 ...
随机推荐
- Hadoop部署启动异常问题排查
hadoop的日志目录(/home/hadoop/app/hadoop-2.6.4/logs) 1.hadoop启动不正常用浏览器访问namenode的50070端口,不正常,需要诊断问题出在哪里: ...
- 转:GRADLE构建最佳实践
转自: http://www.figotan.org/2016/04/01/gradle-on-android-best-practise/#section-2 随着谷歌对Eclipse的无情抛弃和对 ...
- Interleaving String——是否由两个string交叉、DP
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- Async.js解决Node.js操作MySQL的回调大坑
因为JavaScript语言异步特性.在使用Node.js运行非常多操作时都会使用到回调函数,当中就包含訪问数据库.假设代码中的业务逻辑略微复杂一点,回调一层层嵌套.那么代码非常easy进入Callb ...
- Linux视频培训教程
很详尽的Linux培训教程,既包含日常工作常常要用到的实践及技巧,又包含Linux认证及系统管理及架构,讲的很不错.最关键的.这么具体,完整的教程还是免费的.花了点时间拿它整理了下. 第一部分: Li ...
- JavaScript-4.1-简单的表单操作,函数用法---ShinePans
<html> <head> <meta http-equiv="content-type" content="text/html;chars ...
- Swift初窥----语法进阶
缺省绑定(Optional Binding 自己主动置空) 通过在类型变量后,加上?,能够实现缺省绑定为nil var window: UIWindow? 就是说,假设不正确window赋值,则win ...
- 在 Linux 多节点安装配置 Apache Zookeeper 分布式集群
规划: 三台物理服务器就形成了(法定人数).对于高可用性集群,您可以使用高于3的任何奇数.例如,如果设置5台服务器,则集群可以处理两个故障节点等. 物理服务器需要开启的端口 2888 , 3888 和 ...
- HDOJ Oulipo 1686【KMP】
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- java 开发环境安装
一.在mac上安装jdk 1. 下载Mac版本的JDK并安装 http://www.oracle.com/technetwork/java/javase/downloads/index.ht ...