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. sql 日期格式

    select CONVERT(varchar(10), getDate(),121) --不要时间2002-01-01 select CONVERT(varchar(10), getDate(),12 ...

  2. 电脑组装DIY

    技嘉主板:B150M-D3H 网卡驱动: CPU: 风扇: 机箱: 显示器:

  3. 浅谈JSONObject与JSONArray的区别

    例如:一个json字符串如下: { "type":[{"a","1"},{"a","2"},{&qu ...

  4. bash中 2>&1 & 的解释

    1.首先,bash中0,1,2三个数字分别代表STDIN_FILENO.STDOUT_FILENO.STDERR_FILENO,即标准输入(一般是键盘),标准输出(一般是显示屏,准确的说是用户终端控制 ...

  5. MethodInfo类的一般使用

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

  6. Eclipse SVN文件冲突及不能直接提交情况

    下图为Eclipse SVN使用过程中存在文件冲突的情形. 以下是三种冲突情形及相应解决办法: 1.简单的文件版本冲突 情形:A改变了文件的头部,B改变了文件的尾部,如果两者改动互不影响,SVN可以智 ...

  7. Linux命令:history

    显示历史(执行过的)命令. history [n] history -c history -d offset history -anrw [filename] history -p arg [arg ...

  8. vscode-nextgenas编译配置

    文档:https://github.com/BowlerHatLLC/vscode-nextgenas/wiki/asconfig.json asconfig.json { "config& ...

  9. .NET 基础知识

    .net程序基本编写.执行流程(c#)       1>编写c#代码,保存为.cs文件.       2>通过csc.exe程序来将.cs文件编译为.net程序集(.exe或.dll).此 ...

  10. React/anu实现弹出层2

    这次是使用了一个比较罕见的APIReactDOM.unstable_renderSubtreeIntoContainer,ReactDOM.unstable_renderSubtreeIntoCont ...