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. PHP5 的五种常用模式

    PHP5 的五种常用模式. 工厂模式 最初在设计模式 一书中,许多设计模式都鼓励使用松散耦合.要理解这个概念,让我们最好谈一下许多开发人员从事大型系统的艰苦历程.在更改一个代码片段时,就会发生问题,系 ...

  2. maven插件之checkstyle

    checkstyle的eclipse插件已经在eclipse中有讲过,用于开发者自查用.但是不能保证开发者能按照checkstyle进行改正或者自查,因此就需要对未checkstyle通过的代码不能编 ...

  3. linux环境运行java项目并有外部引用jar

    eclipse目录结构: linux目录结构: lib目录结构: 其中除了IMT_ENCODING_DSP.jar其余的都是外部引用的jar IMT_ENCODING_DSP.jar是java项目打包 ...

  4. ORM 的基本操作

    https://www.cnblogs.com/sss4/p/7070942.html

  5. mui页面交互

    1.页面a准备函数 function hideBackBtn() { // $('.menua').removeClass('mui-icon-back').addClass('mui-icon-ba ...

  6. 数据结构:Stack

    Stack设计与实现 Stack基本概念 栈是一种 特殊的线性表 栈仅能在线性表的一端进行操作 栈顶(Top):允许操作的一端 栈底(Bottom):不允许操作的一端 Stack的常用操作 创建栈 销 ...

  7. eclipse无法加载主类错误(项目上红色感叹号问题解决)

    在用eclipse运行一个简单的继承程序时,在点击运行时提示如下: 点击process后,提示无法加载主类错误 在网上一直没找到原因,连helloword程序都无法正常运行了,而且此时我看到文件项目中 ...

  8. 判断页面是否添加了W3C声明

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 使用__slots__限制实例的属性

    1.给实例化的对象添加新的属性 看下面一段代码,然后给实例化的对象s添加或者修改属性 class Student(object): name='china' s = Student() s1=Stud ...

  10. SQL Server Assembly (SQL CLR) 还原数据库后的问题

    最近弄项目迁移的时候遇到还原数据库(SQL Server 2008)后遇到的一个问题: 消息 10314,级别 16,状态 11,第 1 行 在尝试加载程序集 ID 65536 时 Microsoft ...