Codeforces Round #394 (Div. 2)
前一半是刚刚打完比赛的时候写的……不知为啥手腕有点僵,估计是前一个小时用力过度了吧= =
前四题看着还好,后两题就有点懵逼了……现在还不知道E题的题意到底是啥……
不管了……还没找着官方题解,贴一下自己的做法算了……
A显然是傻逼题啊……没注意到a,b都是0的情况,被hack了一次……
#include<cstdio>
using namespace std;
int main(){
int a,b;
scanf("%d%d",&a,&b);
if(a==&&b==)printf("NO");
else{
if(a>b){
int t=a;
a=b;
b=t;
}
printf(b-a<=?"YES":"NO");
}
return ;
}
B也是傻逼题,暴力判断就行……
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool judge();
int n,m,a[],b[];
int main(){
bool ok=false;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++)scanf("%d",&b[i]);
for(int i=;i<n;i++){
if(judge()){
ok=true;
break;
}
rotate(a+,a+,a+n+);
}
printf(ok?"YES":"NO");
return ;
}
bool judge(){
int tmp=(a[]-b[]+m)%m;
for(int i=;i<=n;i++)if((a[i]-b[i]+m)%m!=tmp)return false;
return true;
}
C也是傻逼题,枚举三种符号出现在哪三行,其余的行就不用动了。
为了防止花式TLE我写了预处理代价……
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
const int maxn=;
char s[maxn];
int n,m,f[maxn][],ans=0x3f3f3f3f;
int main(){
scanf("%d%d",&n,&m);
memset(f,,sizeof(f));
for(int i=;i<n;i++){
scanf("%s",s);
for(int j=;j<m;j++){
if(isdigit(s[j]))f[i][]=min(f[i][],min(j,m-j));
else if(islower(s[j]))f[i][]=min(f[i][],min(j,m-j));
else if(s[j]=='#'||s[j]=='*'||s[j]=='&')f[i][]=min(f[i][],min(j,m-j));
}
}
for(int i=;i<n;i++)for(int j=;j<n;j++)if(i!=j)for(int k=;k<n;k++)if(i!=k&&j!=k)ans=min(ans,f[i][]+f[j][]+f[k][]);
printf("%d",ans);
return ;
}
D也不难吧……看了看觉得就是按排名贪心,sort一下就好了……
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
struct A{
int x,pos;
bool operator<(const A &a)const{return x<a.x;}
}c[maxn];
int n,a[maxn],b[maxn],l,r,last=-1e9+;
int main(){
scanf("%d%d%d",&n,&l,&r);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++){
scanf("%d",&c[i].x);
c[i].pos=i;
}
sort(c+,c+n+);
bool ok=true;
for(int i=;i<=n;i++){
b[c[i].pos]=max(l,last+a[c[i].pos]+);
last=b[c[i].pos]-a[c[i].pos];
if(b[c[i].pos]>r){
ok=false;
break;
}
}
if(ok)for(int i=;i<=n;i++){
if(i>)printf(" ");
printf("%d",b[i]);
}
else printf("-1");
return ;
}
E听说主要考读题……药丸啊药丸
我理解的题意是说所有边长度为1,边之间只能成直角或平角,问树是否可以画在平面上……
反正n的范围这么小,找个重心之后求个bfs序,按bfs序暴搜……反正我过了Pretest,跑的还挺快……
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn=,dx[]={,,-,},dy[]={-,,,};
void getcenter(int);
void dfs(int);
vector<int>G[maxn];
bool vis[maxn][maxn]={false};
int size[maxn]={},son[maxn]={},id[maxn],tim=;
int n,center=,x,y,du[maxn]={},a[maxn],b[maxn],p[maxn];
bool ok=false;
int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
du[x]++;
du[y]++;
}
bool bad=false;
for(int i=;i<=n;i++)if(du[i]>){
bad=true;
break;
}
if(bad){
printf("NO");
return ;
}
getcenter();
x=center;
getcenter(center);
a[x]=b[x]=;
vis[][]=true;
dfs();
if(ok){
printf("YES\n");
for(int i=;i<=n;i++)printf("%d %d\n",a[i],b[i]);
}
else printf("NO");
return ;
}
void getcenter(int x){
queue<int>q;
int tim=;
fill(p,p+n+,);
q.push(x);
while(!q.empty()){
x=q.front();
q.pop();
id[++tim]=x;
size[x]=;
for(int i=;i<(int)G[x].size();i++)if(G[x][i]!=p[x]){
p[G[x][i]]=x;
q.push(G[x][i]);
}
}
for(int i=n;i;i--){
x=id[i];
size[p[x]]+=size[x];
if(size[x]>size[son[p[x]]])son[p[x]]=x;
}
for(int i=;i<=n;i++){
x=id[i];
if(!center||max(n-size[x],size[son[x]])<max(n-size[center],size[son[center]]))center=x;
}
}
void dfs(int k){
if(k==n+){
ok=true;
return;
}
register int x=id[k];
for(int i=;i<;i++)if(!vis[a[p[x]]+dx[i]+][b[p[x]]+dy[i]+]){
a[x]=a[p[x]]+dx[i];
b[x]=b[p[x]]+dy[i];
vis[a[x]+][b[x]+]=true;
dfs(k+);
if(ok)return;
vis[a[x]+][b[x]+]=false;
}
}
UPD:理解错了题意了…… 然后就WA了,英死早……
话说这次的比赛不太资瓷啊……room老是炸,中间好不容易能看了,lock了C之后看别人的代码,看着看着突然发现有个傻小伙把m-j写成了n-j+1,火速造了个小数据,交上去之后也不知到底hack上了没有……
本来做出来了四道水题,然后因为CF的系统不太资瓷结果unrated了……不好玩……
Codeforces Round #394 (Div. 2)的更多相关文章
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)
E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #394 (Div. 2) 颓废记
昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造
E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(dfs)
http://codeforces.com/contest/761/problem/E 题意:给出一棵树,现在要把这棵树上的结点放置在笛卡尔坐标上,使得每一条边与x轴平行或者与y轴平行.输出可行解,即 ...
- Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)
http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends(暴力)
http://codeforces.com/contest/761/problem/B 题意: 有一个长度为l的环形跑道,跑道上有n个障碍,现在有2个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...
随机推荐
- PHP开发微信公众号(一)二维码的获取
要开发微信公众号,首先进行需要注册一个,然后认证.这就不用多说了. 当然如果没有,也可以去申请一个测试号来使用,地址:https://mp.weixin.qq.com/debug/cgi-bin/sa ...
- ubuntu->桌面版-常用设置
1.目前使用unity桌面 ,使用Gnome,未来将会采用 Qt/QML 语言写的桌面 2.汉化 系统: 在 设置(setting)->语言支持(language support)->选择 ...
- mysql 存储过程和游标
CREATE DEFINER=`root`@`localhost` PROCEDURE `NewProc`() BEGIN #Routine body goes here... DECLARE ite ...
- Comparable比较器和Comparator比较器
1.Comparable比较器 在Arrays类中存在sort()排序方法,此方法可以直接对对象数组进行排序. public static void sort(Object[] a 根据元素的自然顺序 ...
- 动态树Link-cut tree(LCT)总结
动态树是个好玩的东西 LCT题集 预备知识 Splay 树链剖分(好像关系并不大) 动态树(Link-cut tree) 先搬dalao博客 什么是LCT? 动态树是一类要求维护森林的连通性的题的总称 ...
- 【Python】端口扫描脚本
0x00 使用模块简介 1.optparse模块 选项分析器,可用来生成脚本使用说明文档,基本使用如下: import optparse #程序使用说明 usage="%prog -H ...
- Ubuntu系统下移动宽带自动启用设置
对于需要自动移动联网的Ubuntu系统(安装了4G移动手机卡的),步骤如下: . 在终端编辑自启动文件:sudo gedit /etc/rc.local 2. 在最后一句exit 0的上⾯面加上如下指 ...
- python 中mysql数据库的读写
1.读取数据库 import pymysql id=[] name=[] explain=[] db=pymysql.Connection(host=,user="root", p ...
- 2016424王启元 Exp2 后门原理与实践
一.实验准备 1.在实验前关闭或退出了防火墙.360杀毒软件.电脑卫士等所有的电脑保护软件,避免在实验过程中攻击时被拒绝. 2.使用Windows获linux shell (1)在Wind ...
- How to remove constantly launching services on Mac OS X
Even after you uninstall it, some Mac OS X software just won’t quit nagging you or notifying you of ...