Codeforces Beta Round #9 (Div. 2 Only)

http://codeforces.com/contest/9

A

gcd水题

 #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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int gcd(int a,int b){
if(b==) return a;
return gcd(b,a%b);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,m;
cin>>n>>m;
n=max(n,m);
int fz=-n+;
int fm=;
int d=gcd(fz,fm);
// cout<<fz<<" "<<fm<<endl;
cout<<fz/d<<"/"<<fm/d<<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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
struct Point{
ll x,y;
}a[]; double dist[][]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
ll n,vb,vs;
cin>>n>>vb>>vs;
for(int i=;i<=n;i++){
cin>>a[i].x;
a[i].y=;
}
ll sx,sy;
cin>>sx>>sy;
for(int i=;i<=n;i++){
dist[][i]=sqrt(sqr(a[].x-a[i].x)+sqr(a[].y-a[i].y));
}
for(int i=;i<=n;i++){
dist[i][]=sqrt(sqr(a[i].x-sx)+sqr(a[i].y-sy));
}
double ans=1e18;
ll pos=;
for(int i=;i<=n;i++){
if(a[i].x!=){
double t1=dist[][i]/vb;
double t2=dist[i][]/vs;
if(ans>=t1+t2){
ans=t1+t2;
pos=i;
}
}
}
cout<<pos<<endl;
}

C

dfs

 #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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
map<ll,int>mp;
ll n;
int ans; void dfs(int pos){
if(pos>n) return;
if(!mp[pos]){
ans++;
mp[pos]=;
}
else return;
dfs(pos*);
dfs(pos*+);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
cin>>n;
dfs();
cout<<ans<<endl;
}

D

参考博客:http://www.cnblogs.com/qscqesze/p/5414271.html

DP

dp[i][j]表示当前用了i个节点,高度小于等于j的方案数

dp[i][j] = sigma(dp[k][j-1]*dp[i-k-1][j-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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ long long dp[][]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,h;
cin>>n>>h;
for(int i=;i<=n;i++){
dp[][i-]=;
for(int j=;j<=n;j++){
for(int k=;k<j;k++){
dp[j][i]+=dp[k][i-]*dp[j-k-][i-];
}
}
}
cout<<dp[n][n]-dp[n][h-]<<endl;
}

E

题意:给出n个点,m条边,问是否能通过加一些边,使得n个点构成有且仅有n条边的单个环

直接构造就好

 #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 maxn 1000010
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int fa[];
int d[];
vector<pair<int,int> > ve,ans;
int Find(int x){
int r=x,y;
while(x!=fa[x]){
x=fa[x];
}
while(r!=x){
y=fa[r];
fa[r]=x;
r=y;
}
return x;
}
void join(int x,int y)
{
int xx=Find(x);
int yy=Find(y);
if(xx!=yy) fa[xx]=yy;
}
int main(){
int n,m;
cin>>n>>m;
int v,u;
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
cin>>u>>v;
ve.push_back(make_pair(u,v));
join(u,v);
d[v]++,d[u]++;
if(d[u]>||d[v]>){
cout<<"NO"<<endl;
return ;
}
}
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(d[j]<=&&d[i]<=&&Find(i)!=Find(j))
{
ans.push_back(make_pair(j,i));
join(i,j);
d[i]++,d[j]++;
}
}
}
for(int i=;i<=n;i++){
if(d[i]!=){
for(int j=;j<i;j++){
if(d[j]==){
ans.push_back(make_pair(j,i));
join(i,j);
d[i]++,d[j]++;
}
}
}
}
for(int i=;i<=n;i++)
if(d[i]==)ans.push_back(make_pair(i,i));
int p = Find();
for(int i=;i<=n;i++)
if(Find(i)!=p){
cout<<"NO"<<endl;
return ;
}
cout<<"YES"<<endl;
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++)
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}

Codeforces Beta Round #9 (Div. 2 Only)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

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

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

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

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

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

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

  10. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

随机推荐

  1. REST-assured 2发送消息代码重构

    将获取token的方法封装到公共类 #java package date811; import io.restassured.response.Response; import org.testng. ...

  2. RouterOS 设定NAT loopback (Hairpin NAT)回流

    In the below network topology a web server behind a router is on private IP address space, and the r ...

  3. php实现AES/CBC/PKCS5Padding加密解密(又叫:对称加密)

    今天在做一个和java程序接口的架接,java那边需要我这边(PHP)对传过去的值进行AES对称加密,接口返回的结果也是加密过的(就要用到解密),然后试了很多办法,也一一对应了AES的key密钥值,偏 ...

  4. Lunce编程模型

    问题的场景: 解决方案:都是来自于科技论文 ============================================================================== ...

  5. html5 如何实现客户端验证上传文件的大小

    在HTML 5中,现在可以在客户端进行文件上传时的校验了,比如用户选择文件后,可以 马上校验文件的大小和属性等.本文章向码农介绍html5 如何实现客户端验证上传文件的大小,感兴趣的码农可以参考一下. ...

  6. mybatis匹配字符串的坑

    where语句中我们经常会做一些字符串的判断,当传入的字符串参数为纯数字时,在mybatis的条件语句test里匹配全数字字符串需要注意会有如下现象: 所以里面的字符串需要加单引号,mybatis是匹 ...

  7. Android应用程序的自动更新升级(自身升级、通过tomcat)(转)

    Android应用程序的自动更新升级(自身升级.通过tomcat) http://blog.csdn.net/mu0206mu/article/details/7204746 刚入手android一个 ...

  8. JS吧数字转成2进制 8进制16进制数据

    ; number.toString(); //转成2进制 number.toString();//转成8进制 number.toString();//转成10进制 number.toString(); ...

  9. 机器学习入门-交叉验证选择参数(数据切分)train_test_split(under_x, under_y, test_size, random_state), (交叉验证的数据切分)KFold, recall_score(召回率)

    1. train_test_split(under_x, under_y, test_size=0.3, random_state=0)  # under_x, under_y 表示输入数据, tes ...

  10. time 时间内置模块3种形态的转化

    import time print(time.time())  #获得时间戳 1526998642.877814 print(time.sleep(2))  #停止2秒 print(time.gmti ...