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. 过度使用DBLINK做系统集成会带来的问题

    过度使用DBLINK做系统集成会带来很多问题,问题主要由以下几点: 1. 大量消耗数据库资源: 本地系统每通过DBLINK链接远端系统一次,都会生成一个本地session,如本地session不退出或 ...

  2. [Java基础] Java float保留两位小数或多位小数

    方法1:用Math.round计算,这里返回的数字格式的. float price=89.89; int itemNum=3; float totalPrice=price*itemNum; floa ...

  3. [UE4]事件代理,无输出参数,蓝图中不需要绑定

    .h UFUNCTION(BlueprintImplementableEvent, meta=(DisplayName = "LoginSuccess")) void LoginS ...

  4. mysql 字符集排查

    mysql 字符集排查 库级别 SELECT * FROM information_schema.schemata WHERE schema_name NOT IN ( 'information_sc ...

  5. Logistic回归的两种形式y=0/1,y=+1/-1

    第一种形式:y=0/1 第二种形式:y=+1/-1 第一种形式的损失函数可由极大似然估计推出: 第二种形式的损失函数:  , 参考:https://en.wikipedia.org/wiki/Loss ...

  6. API网关Kong系列(四)认证配置

    目前根据业务需要先介绍2种认证插件:Key Authentication 及 HMAC-SHA1 认证  Key Authentication 向API添加密钥身份验证(也称为API密钥). 然后,消 ...

  7. javascript节点操作replaceChild()

    replaceChild(a,b)是用来替换文档中的已有元素的 参数a:要插入的节点, 参数b:要替换的节点 var oDiv = document.getElementById("guoD ...

  8. 启动 node 文件时附带参数

    cmd: node app.js hello app.js var args = process.argv; console.log(args);//[ 'C:\\Program Files\\nod ...

  9. relocation error: /usr/lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference 问题解决

    在建立一个错误的软连接到ld-linux-x86-64.so.2时,悲剧就这么发生了.此时大部分命令都不能使用,SSH当然也不能登录了.这个时候一定不要退出终端. 有人说那就把软连接复原吧,可是ln也 ...

  10. sklearn的estimator

    estimator的工作流程 在sklearn中,估计器(estimator)是一个重要的角色,分类器和回归器都属于estimator.在估计器中有有两个重要的方法是fit和transform. fi ...