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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Beta Round #32 (Div. 2, Codeforces format)

    Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...

  4. Codeforces Beta Round #31 (Div. 2, Codeforces format)

    Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...

  5. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  6. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  7. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  8. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

随机推荐

  1. MVC基于角色权限控制--权限过滤

    用户访问服务器实际上就是访问控制器下的方法,因此在权限控制就是控制器方法的访问权限 为了方便控制,我们可以建立一个基类控制器(BaseController),让需要的控制器继承这个控制器即可,在Bas ...

  2. Linux查看系统中socket状态

    当我们打开的socket数量很多时,netstat就会变得慢了,有什么办法可以快速查看系统中socket状态? IPv4: $ cat /proc/net/sockstat sockets: used ...

  3. vector 内存释放相关

    在使用vector 存储char 类型时 new的数据 在vecto 执行rerase的时候或者 单项执行clear 内存是不能被释放的. 比如有下面的一个测试: class SnapshotInfo ...

  4. MethodInfo类的一般使用

    1.MethodInfo类是在System.Reflection命名空间底下,既然是在Reflection空间底下.故名思议关于反射相关的操作,其中比较重要的方法是Invoke()方法,它 是加载相同 ...

  5. javascript:width,innerwidth和outerwidth的区别

    width()方法用于获得元素宽度 innerWidth()方法用于获得包括内边界(padding)的元素宽 outerWidth()方法用于获得包括内边界(padding)和边框(border)的元 ...

  6. Java IO流学习总结六:ByteArrayInputStream、ByteArrayOutputStream

    类的继承关系 InputStream |__ ByteArrayInputStream OutputStream |__ ByteArrayOutputStream ByteArrayInputStr ...

  7. 【384】reduce归纳、map映射、filter筛选 的用法

    参考:4. Map, Filter and Reduce — Python Tips 0.1 documentation 参考:Python的functools.reduce用法 Map:映射,对于列 ...

  8. jquery 初始化数据 添加html 第一次玩0.0

    /** * Created by Eee_xiang on 2018/04/12. * 联动响应事件 */ (function () { $.linkEvent = function (options ...

  9. Windows下查看端口常用命令以及关闭端口的方法

    1.C:\Users\JavaKam> netstat -ano|findstr 1099 TCP LISTENING TCP [::]: [::]: LISTENING 2.出现: C:\Us ...

  10. C#调用Delphi接口(ITest = interface)

    首先创建一个delphi的DLL工程 library testintfdll; { Important note about DLL memory management: ShareMem must ...