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. ESXi 上创建CentOS虚拟机

    之前介绍了ESXi上添加存储.本篇介绍一下在ESXi上创建CentOS虚拟机. 方法/步骤   登陆ESXi,选择“创建/注册虚拟机” 选择“创建新的虚拟机” 给装的虚拟机命名,并选择操作系统及版本 ...

  2. day22-类的多态

    一.多态 多态的概念是应用于Java和C#这一类强类型语言中,而Python崇尚“鸭子类型”.所谓多态:调用的方法是同一个,但是执行的代码或者说现象不一样,此时就称为多态 #我们编写了名为Animal ...

  3. vue:绑定数据的vue页面加载会闪烁问题

    1:在挂在数据的容器加上属性 v-cloak 2:在css中添加如下代码 但有时候还是会不起作用,可能原因有两个 2.1:display属性被更高权限的display属性覆盖了,我们增加权限就好了 2 ...

  4. JS 实现分页打印

    在调用window.print()时,可以实现打印效果,但内容太多时要进行分页打印. 在样式中有规定几个打印的样式 page-break-before和page-break-after CSS属性并不 ...

  5. Arcgis map export or print Error: Cannot map metafile into memory. Not enough memory

      Arcgis map export or print Error: Cannot map metafile into memory. Not enough memory Link: https:/ ...

  6. ArcGIS案例学习笔记-找出最近距离的垂线

    ArcGIS案例学习笔记-找出最近距离的垂线 联系方式:谢老师,135-4855-4328,xiexiaokui@qq.com 目的:对于任意矢量要素类,查找最近距离并做图 数据: 方法: 0. 计算 ...

  7. 小程序:pages/index/index/出现脚本错误或未正确调用Page()

    第一次尝试玩小程序,配置好以后报错.pages/index/index/出现脚本错误或未正确调用Page() 才发现解决的方式是:新建的文件默认是没有page()的,所以你需要在.js文件中加上Pag ...

  8. winform clickonce在线安装

    转 http://swanmsg.blog.sohu.com/162994305.html

  9. 一,Serializer和ModelSerializer

    1.REST Framework概述 Django REST framework是一套基于Django的REST框架,是一个用于构建Web API的功能强大且灵活的工具包. RESTful 简述 Re ...

  10. echart生成饼状图

    //绘制图表. echarts.init(document.getElementById('main')).setOption({ tooltip : { trigger: 'item', //触发类 ...