Codeforces Beta Round #29 (Div. 2, Codeforces format)
Codeforces Beta Round #29 (Div. 2, Codeforces format)
http://codeforces.com/contest/29
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int a[],b[];
for(int i=;i<=n;i++){
cin>>a[i]>>b[i];
}
int flag=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i!=j){
if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i]){
flag=;
}
}
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
B
模拟
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
double l,d,v,g,r;
cin>>l>>d>>v>>g>>r;
double ans=;
if(v*g>d) ans=l/v;
else{
l-=d;
double t=d/v;
ans=t;
double tt=g+r;
int flag=;
while(t>=){
t-=g;
if(t>=){
t-=r;
}
if(t<) flag=;
}
// cout<<t<<endl;
if(flag==){
ans-=t;
}
ans+=l/v;
}
printf("%.7f\n",ans);
}
C
找出一个度为1的点,然后跑dfs。因为值为1e9,所以需要离散化
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
vector<int>ve;
int a[];
int b[];
int d[];
vector<int>V[]; int getid(int x){
return lower_bound(ve.begin(),ve.end(),x)-ve.begin()+;
} void dfs(int pos,int pre){
cout<<ve[pos-]<<" ";
for(int i=;i<V[pos].size();i++){
if(V[pos][i]!=pre){
dfs(V[pos][i],pos);
}
}
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i]>>b[i];
ve.pb(a[i]);
ve.pb(b[i]);
}
sort(ve.begin(),ve.end());
ve.erase(unique(ve.begin(),ve.end()),ve.end());
int pos,pos1,pos2;
for(int i=;i<=n;i++){
pos1=getid(a[i]);
pos2=getid(b[i]);
d[pos1]++,d[pos2]++;
V[pos1].pb(pos2);
V[pos2].pb(pos1);
}
for(int i=;i<=n;i++){
pos1=getid(a[i]);
pos2=getid(b[i]);
if(d[pos1]==){
pos=pos1;
break;
}
if(d[pos2]==){
pos=pos2;
break;
}
}
dfs(pos,);
}
D
跑两个叶子结点的最短路,看看最后的个数是不是2*n-1
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
vector<int>ve[];
int vis[];
int d[];
vector<int>ans; void dfs(int pos,int pre,int last,vector<int>tmp){
vis[pos]=;
if(pre!=) {
tmp.pb(pos);
}
if(pos==last){
for(int i=;i<tmp.size();i++){
ans.pb(tmp[i]);
}
return;
}
for(int i=;i<ve[pos].size();i++){
if(!vis[ve[pos][i]]&&ve[pos][i]!=pre){
dfs(ve[pos][i],pos,last,tmp);
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int u,v;
for(int i=;i<n;i++){
cin>>u>>v;
ve[u].pb(v);
ve[v].pb(u);
d[u]++,d[v]++;
}
int co=;
for(int i=;i<=n;i++){
if(d[i]==){
co++;
}
}
vector<int>son;
son.pb();
for(int i=;i<=co;i++){
cin>>u;
son.pb(u);
}
son.pb();
ans.pb();
for(int i=;i<son.size()-;i++){
memset(vis,,sizeof(vis));
vector<int>tmp;
tmp.clear();
dfs(son[i],,son[i+],tmp);
}
if(ans.size()==*n-){
for(int i=;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
else{
cout<<-<<endl;
}
}
E
bfs搜索,思路很有趣
标记是用A和B的相对位置进行标记的,懂了这一点这题就解决了
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int n,m;
vector<int>ve[];
int pre[][][];
bool book[][];
vector<int>ans[]; bool bfs(){
pre[][n][]=-;
pair<int,int>p,pp;
p=make_pair(,n);
queue<pair<int,int> >Q;
Q.push(p);
while(!Q.empty()&&pre[n][][]==){
p=Q.front();
Q.pop();
int p1=p.first,p2=p.second;
for(int i=;i<ve[p1].size();i++){
if(!book[ve[p1][i]][p2]){
book[ve[p1][i]][p2]=;
for(int j=;j<ve[p2].size();j++){
if(ve[p1][i]!=ve[p2][j]){
if(pre[ve[p1][i]][ve[p2][j]][]==){
pre[ve[p1][i]][ve[p2][j]][]=p1;
pre[ve[p1][i]][ve[p2][j]][]=p2;
pp=make_pair(ve[p1][i],ve[p2][j]);
Q.push(pp);
}
}
}
}
}
}
if(pre[n][][]==) return false;
int x=n,y=,z;
while(x>){
ans[].pb(x);
ans[].pb(y);
z=x;
x=pre[x][y][];
y=pre[z][y][];
}
return true;
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
int u,v;
for(int i=;i<=m;i++){
cin>>u>>v;
ve[u].pb(v);
ve[v].pb(u);
}
if(bfs()){
cout<<ans[].size()-<<endl;
for(int i=;i<;i++){
for(int j=ans[i].size()-;j>=;j--){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
}
else{
cout<<-<<endl;
} }
Codeforces Beta Round #29 (Div. 2, Codeforces format)的更多相关文章
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序
C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 拓扑排序
C. Mail Stamps One day Bob got a letter in an envelope. Bob knows that when Berland's post offic ...
- Codeforces Beta Round #32 (Div. 2, Codeforces format)
Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...
- Codeforces Beta Round #31 (Div. 2, Codeforces format)
Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- linux指令tar笔记
tar 工具常用选项如表所列. 选项 说明 -c 创建存档文件,与-x相斥 -t 列出档案文件的文件列表 -x 解包存档文件,与-c相斥 -A 合并存档文件 -d 比较存档文件与源文件 - ...
- selenium报错
Python 2.7.15 selenium 2.53.6 Firefox 47.0.1 pycharm 2017.3.7 # coding:utf-8 from selenium import ...
- react-native Animated, 旋转动画
Animated 仅封装了四个可以动画化的组件: View.Text.Image.ScrollView 可以使用 Animated.createAnimatedComponent()来封装你自己的组件 ...
- 26个Jquery使用小技巧(转)
下面列出了一些Jquery使用技巧.比如有禁止右键点击.隐藏搜索文本框文字.在新窗口中打开链接.检测浏览器.预加载图片.页面样式切换.所有列等 高.动态控制页面字体大小.获得鼠标指针的X值Y值.验证元 ...
- vue.js 初级之一
vue.js 是一个构建数据驱动的 web 界面 渐进式驱动框架. 引用的话,直接使用script标签引入就可以了: <script src="./lib/vue.js"&g ...
- python语言中的数据类型之元组
数据类型 元组 tuple 元组:不可变类型 用途:元组就是一个不可变的列表,当需要存不改动的值时可用元组 定义方式:在()内用逗号分隔开多个任意类型的元素 t=(1,2.2,'aa',( ...
- win10 任务栏锁定,win键没反应
现象:之前用win10,换成win10专业版后,安装360优化系统,过了几天后突然发现任务栏好像被锁定一般,按windows键没有任何反应,任务栏打开的文件,图片等等右键也没有反应,讲道理应该有关闭选 ...
- Emac
https://emacs-china.org/ 启动 console模式的emacs,$emacs -nw 学习参考: 1)<21天精通emacs> 2)Emacs常用命令简集. 3)& ...
- thinkphp中使用phpexecl多表格应用
去PHPExcel官网下载相应的版本,放到thinkphp3.2版本下的ThinkPHP/Library/Vendor/PHPExcel文件夹下 导出表格: //多个单元格(已测试) public ...
- vscode项目配置 vue-loader-webpack
使用vsCode进行项目配置 一.准备工作 1.下载Visual Studio Code 下载地址 2.打开vscode,根据自己需求下载相应插件,可以提高工作效率. 点击下角选项(我作了红框标记), ...