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个人,给出他们每过多少米碰到障碍,判断他们跑的是不是 ...
随机推荐
- iOS tableview性能优化及分析
1.最常用的就是cell的重用, 注册重用标识符 每次滑动cell时需要先去缓存池中寻找可循环利用的cell,如果没有则再重新创建cell 2.减少cell中控件的数量 view对象尽量缩减控件的数量 ...
- (STM32F4) IAP程式碼實現
IAP學習, 主要想了解實際上程式碼放在不同的Flash位置如何轉跳且執行. 我的應用程序只做了Pin12, Pin13 LED閃爍來分辨我的 App1 跟 App2的程式碼 App1 程式碼 int ...
- np.random.normal()
高斯分布(Gaussian Distribution)的概率密度函数(probability density function): \[ f(x)=\frac1{\sqrt{2\pi}\sigma}\ ...
- [转] Ansible 系列之 Playbooks 剧本
[From] https://www.cnblogs.com/hanyifeng/p/6435875.html 一.Playbooks 介绍 1.Playbooks是Ansible的配置,部署和编排语 ...
- 剑指offer——面试题18.1:删除链表中重复的节点
// 面试题18(二):删除链表中重复的结点 // 题目:在一个排序的链表中,如何删除重复的结点?例如,在图3.4(a)中重复 // 结点被删除之后,链表如图3.4(b)所示. #include &l ...
- maven相关的说明以及通过它来创建项目
1.什么是maven maven的本质是一个项目构建工具 2.maven的作用 那么作为一个项目构建工具我们又为什么要使用它以及好处呢 首先项目构建的本质是什么:项目代码从源代码到程序文件的过程是代码 ...
- SpringBoot学习(一)
一.Spring Boot Spring是JavaEE轻量级代替品.无需开发重量级的(EJB),Spring为企业级Java开发提供了一种相对简单的方法,通过依赖注入和面向切面编程,用简单的POJO对 ...
- 使用Maven运行测试提示Module sdk 1.5的解决方法
解决方法: 1. 配置Project Structure 2. 在MAVEN_HOME/conf/setting.xml中添加profile 3. 在Maven项目的pom.xml文件里添加标签 三种 ...
- 1、The Fctory Pattern(工厂模式:解决对象创建问题)
The Fctory Pattern 处理对象创建,客户端可以申请一个对象而不用知道对象被那个class创建.可以方便地解耦对象的使用和创建,有两种实现,工厂方法和抽象工厂. Method(工厂方法 ...
- Java_方法的基本语法格式
[修饰符] 返回值类型 方法名称([参数列表]){ 方法体 } [ ]中的内容是可有可无的 暂时将方法的修饰符编写为 public static 返回值类型有两种情况 : 第一种:无返回值类型,也就是 ...