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个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...
随机推荐
- js实现抛物线
这个是很简单的一种方式,利用了css3的transition属性 <!DOCTYPE html> <html lang="en" style="widt ...
- 缩点 CF893C Rumor
CF893C Rumor 有n个人,其中有m对朋友,现在你有一个秘密你想告诉所有人,第i个人愿意出价a[i]买你的秘密,获得秘密的人会免费告诉它的所有朋友(他朋友的朋友也会免费知道),现在他们想出最少 ...
- 2016级算法第二次上机-C.AlvinZH的儿时梦想——坦克篇
872 AlvinZH的儿时梦想----坦克篇 思路 简单题.仔细看题,题目意在找到直线穿过的矩形数最小,不能从两边穿过.那么我们只要知道每一行矩形之间的空隙位置就可以了. 如果这里用二维数组记住每一 ...
- 在makefile中打印错误或警告信息
在makefile中打印警告或者错误消息的方法: $(warning xxxxx) 或者 $(error xxxxx) 输出变量方式为: $(warning $(XXX))
- linux中ls命令使用选项
ls:英文全名:List即列表的意思 -a 列出目录下的所有文件,包括以 . 开头的隐含文件.-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出.-c 输出文件的 i 节 ...
- C运算符和表达式
C语言入门(5)——运算符与表达式 版权声明:本文为博主尹成联系QQ77025077,微信18510341407原创文章,欢迎转载侵权不究. https://blog.csdn.net/yinch ...
- 05-oralce转换函数
to_char() 设置日期的显示格式 to_char() 进行数字格式化{如:to_char(987654321.789,'999,999,999,999,999.9999') 将数字三位一逗号显 ...
- 新建IP核为灰色并显示there is no project open
问题: ise显示there is no project open. “You may browse the IP Catalog but you will not be able to genera ...
- 《C++ Primer(第五版)》知识巩固
运行平台:ubuntu 12.04/GCC 4.8.0 第二章:基本内置类型 1.decltype类型指示符 当我们从表达式的类型来推断要定义的类型时,可以使用decltype()来解析:declty ...
- ie8兼容总结
ie兼容总结 1.页面必须编写规范 doctype 必须申明,否则会让浏览器出现怪异模式呈现,我记得一次是页面没有写doctype,样式的继承也会有问题,明明body里面写了字体样式12px,页面ta ...