Codeforces Beta Round #34 (Div. 2)

http://codeforces.com/contest/34

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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
int a[];
map<int,int>mp; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
a[n+]=a[];
int pos1,pos2,Min=0x3f3f3f3f;
for(int i=;i<=n;i++){
if(abs(a[i]-a[i+])<Min){
Min=abs(a[i]-a[i+]);
pos1=i;
pos2=i+;
}
}
if(pos2==n+) pos2=;
cout<<pos1<<" "<<pos2<<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 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
int a[];
map<int,int>mp; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
int m;
cin>>n>>m;
for(int i=;i<=n;i++) cin>>a[i];
sort(a+,a+n+);
int ans=;
for(int i=;i<=n&&m;i++){
if(a[i]<){
ans-=a[i];
m--;
}
}
cout<<ans<<endl;
}

C

map+vector

 #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 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ map<int,int>mp;
map<int,int>::iterator it;
vector<int>ve; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
cin>>str;
int co=;
for(int i=;i<str.length();i++){
if(str[i]!=','){
co=co*+str[i]-'';
}
else{
mp[co]=;
co=;
}
}
mp[co]=;
for(it=mp.begin();it!=mp.end();it++){
ve.push_back(it->first);
}
ve.push_back(0x3f3f3f3f);
sort(ve.begin(),ve.end());
int pre=ve[];
int flag=;
for(int i=;i<ve.size()-;i++){
if(ve[i+]-ve[i]!=){
//cout<<endl<<ve[i]<<" "<<ve[i+1]<<endl;
if(flag) cout<<',';
if(pre!=ve[i])
cout<<pre<<'-'<<ve[i];
else cout<<pre;
pre=ve[i+];
if(!flag){
flag=;
}
}
}
}

D

题意不好理解,是要求树换一个根结点后的前驱

 #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 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ vector<int>ve[];
int r1,r2;
int n;
int ans[];
int vis[]; void dfs(int pos){
vis[pos]=;
for(int i=;i<ve[pos].size();i++){
if(!vis[ve[pos][i]]){
ans[ve[pos][i]]=pos;
dfs(ve[pos][i]);
}
}
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>r1>>r2;
int a;
for(int i=;i<=n;i++){
if(i!=r1){
cin>>a;
ve[i].push_back(a);
ve[a].push_back(i);
}
}
dfs(r2);
for(int i=;i<=n;i++){
if(i!=r2){
cout<<ans[i]<<" ";
}
}
}

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

  1. Codeforces Beta Round #34 (Div. 2) E. Collisions

    E. Collisions time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Valgrind简单用法 (转)

    转自 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html Valgrind的主要作者Julian Seward刚获得了今年的G ...

  2. c++Builder debug DataSet Visualizer

    c++Builder debug DataSet Visualizer delphi 正常,c++builder报错. fdMemTable->SaveToFile("d:\\DSdb ...

  3. 【JEECG技术文档】JEECG 组织机构导入V3.7

    1.功能介绍 组织机构导入 提供组织机构模版导入功能,使用户更快速的创建组织机构 要使用组织机构导入功能需要完成以下步骤: 1. 下载模版excel 2. 填写组织机构信息 3. 点击导入-选择文件- ...

  4. ActiveMQ 学习

    链接:  http://www.cnblogs.com/zhuxiaojie/p/5564187.html#autoid-1-0-0

  5. js 定义一个对象并且给对象赋值方法

    var  obj={}; obj.a="12"; obj.b="13" var o ={}; o.jsonObj=obj; 取得属性值直接用 obj.a; ob ...

  6. 爬虫介绍+Jupyter Notebook

    什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫    1.php:可以实现爬虫.php被号称是全世界最优美的语言(当然是其自己号称的,就是王婆 ...

  7. python流程控制while和if

    流程控制 1.流程控制if if的4种语法 语法1:   #结构形式 #if条件: # 代码1 # 代码2 # 代码3 # ... key_bak=123 key=int(input('key:')) ...

  8. tomcat8 web工程启动,登陆页面失败问题解决

    编辑该文件context.xml 增加以下内容 <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookie ...

  9. MVC 中Controller返回值类型ActionResult

    下面列举Asp.net MVC中Controller中的ActionResult返回类型 1.返回ViewResult视图结果,将视图呈现给网页 public ActionResult About() ...

  10. ubuntu16.04 64bit 升级到 python3.6

    https://blog.csdn.net/zhao__zhen/article/details/81584933 https://www.codetd.com/article/1967538 htt ...