Codeforces Beta Round #35 (Div. 2)

http://codeforces.com/contest/35

A

这场的输入输出是到文件中的,不是标准的输入输出。。。没注意看,RE了好久。。。

 #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 pb push_back
#define eps 1e-8
#define PI acos(-1.0)
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull; /*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ ifstream cinn("input.txt");
ofstream coutt("output.txt"); int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int u,v;
int b; int a[];
memset(a,,sizeof(a));
cinn>>b;
a[b]=;
for(int i=;i<;i++){
cinn>>u>>v;
swap(a[u],a[v]);
}
for(int i=;i<=;i++){
if(a[i]==){
coutt<<i;
return ;
}
}
return ;
}

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 pb push_back
#define eps 1e-8
#define PI acos(-1.0)
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull; /*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
string s,t,x[][];
int n,m,k,i,j,a,b,o,r; int main(){
// #ifndef ONLINE_JUDGE
freopen ("input.txt","r",stdin);
freopen ("output.txt","w",stdout);
// #endif
cin>>n>>m>>k;
for (o=;o<=k;o++){
cin>>s;
if (s[]=='+'){
cin>>a>>b>>t;
while (){
if (x[a][b]==""){
x[a][b]=t;
break;
}
else {
b++;
if (b>m){
a++;
b=;
if (a>n)
break;
}
}
}
}
else {
cin>>t;
r=;
for (i=;i<=n;i++){
if (r==)
break;
for (j=;j<=m;j++){
if (x[i][j]==t){
r=;
break;
} }
}
if (r==){
cout<<-<<" "<<-<<endl;
}
else {
cout<<i-<<" "<<j<<endl;
x[i-][j]="";
}
}
}
}

C

bfs

 #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 pb push_back
#define eps 1e-8
#define PI acos(-1.0)
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull; /*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
int book[][];
int n,m,k;
struct sair{
int x,y,step;
};
int dir[][]={,,,,,-,-,}; int main(){
// #ifndef ONLINE_JUDGE
freopen ("input.txt","r",stdin);
freopen ("output.txt","w",stdout);
// #endif
cin>>n>>m>>k;
int x,y;
queue<sair>Q;
sair s,e;
for(int i=;i<=k;i++){
cin>>x>>y;
s.x=x,s.y=y,s.step=;
book[x][y]=;
Q.push(s);
}
int last=;
while(!Q.empty()){
s=Q.front();
Q.pop();
for(int i=;i<;i++){
e.x=s.x+dir[i][];
e.y=s.y+dir[i][];
if(e.x>=&&e.x<=n&&e.y>=&&e.y<=m&&!book[e.x][e.y]){
e.step=s.step+;
if(e.step>last) last=e.step;
// cout<<last<<endl;
book[e.x][e.y]=e.step;
Q.push(e);
}
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(book[i][j]==last){
cout<<i<<" "<<j<<endl;
return ;
}
}
}
}

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 pb push_back
#define eps 1e-8
#define PI acos(-1.0)
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull; /*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,x;
int a[]; int main(){
// #ifndef ONLINE_JUDGE
freopen ("input.txt","r",stdin);
freopen ("output.txt","w",stdout);
// #endif
cin>>n>>x;
for(int i=;i<=n;i++){
cin>>a[i];
a[i]=a[i]*(n-i+);
}
sort(a+,a+n+);
for(int i=;i<=n;i++){
x-=a[i];
if(x<){
cout<<i-<<endl;
return ;
} }
cout<<n<<endl;
}

E

扫瞄线,可以用线段树写,不过我是用类似模拟的方法写的

 #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 pb push_back
#define eps 1e-8
#define PI acos(-1.0)
#define maxn 1000005
typedef long long ll;
typedef unsigned long long ull; /*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
multiset<int>ms;
vector<pair<int,int> >ve,ans; int main(){
// #ifndef ONLINE_JUDGE
freopen ("input.txt","r",stdin);
freopen ("output.txt","w",stdout);
// #endif
std::ios::sync_with_stdio(false);
cin>>n;
int l,r,h;
for(int i=;i<n;i++){
cin>>h>>l>>r;
ve.push_back(make_pair(l,h));
ve.push_back(make_pair(r,-h));
}
sort(ve.begin(),ve.end());
int i=,j;
h=;
ms.insert(h);
while(i<ve.size()){
j=i;
do{
if(ve[j].second>){
ms.insert(ve[j].second);
}
else{
ms.erase(ms.find(-ve[j].second));
}
j++; }while(j<ve.size()&&ve[i].first==ve[j].first);
if(h!=*ms.rbegin()){
ans.push_back(make_pair(ve[i].first,h));
ans.push_back(make_pair(ve[i].first,h=*ms.rbegin()));
}
i=j;
}
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
}

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

  1. Codeforces Beta Round #35 (Div. 2) E. Parade(扫描线)

    题目链接 只要会做,周长并,这题肯定有思路. 有个小地方敲错了,细心啊,扫描线,有一段时间没写过了,还有注意排序的问题,很重要. #include <iostream> #include ...

  2. Codeforces Beta Round #18 (Div. 2 Only)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. MySQL把一个大表拆分多个表后,如何解决跨表查询效率问题

    大表分表后每个表的结构相同,可以用sql的union 比如a,b表结构相同可以通过union来联接 select * from aunion allselect * from bwhere.... 其 ...

  2. 对象 Object

    在js 中创建最简单的对象,然后给它添加属性或者方法 示例如下: var obj = new Object(); //或者 var obj = {}; obj.name = '张三'; obj.fun ...

  3. VC中明明已经添加了头文件却还提示未定义的问题

    我在VS中编译程序遇到这个错误:error C3861: 'ReadDirectoryChangesW': identifier not found, even with argument-depen ...

  4. OC copy mutableCopy, 浅拷贝,深拷贝

    copy与mutableCopy都是深拷贝,区别是mutableCopy拷贝出的对象是可变的. OC对象基本都是通过指针访问,所以一般情况下,通过对指针的赋值都是浅拷贝,即只是拷贝了一份对象的指针,对 ...

  5. C语言复习:字符串和一级指针

    字符串基本操作 字符数组初始化方法 int main() {     //1 {}号法 初始化列表     //数组初始化有2种方法 默认元素个数.指定元素个数     char buf1[] = { ...

  6. 【x】 PAT/BasicLevel_C++/1002. 写出这个数 (20).cpp

    C++中的to_string()函数[C++11支持] - Bravo Yeung-羊较瘦之自留地 - CSDN博客https://blog.csdn.net/lzuacm/article/detai ...

  7. Redis进阶实践之九 独立封装的RedisClient客户端工具类(转载9)

    Redis进阶实践之九 独立封装的RedisClient客户端工具类 一.引言 今天开始有关Redis学习的第九篇文章了,以后肯定会大量系统使用Redis作为缓存介质,为了更好的更好的Redis,自己 ...

  8. 15.Colection集合和Iterator接口.md

    目录 1.Collection 1.1概念 1.1遍历方法-Lambda表达式 1.2遍历方法-Iterator接口 1.3使用Lambda方法遍历Iterator接口 1.4使用Foreach方法遍 ...

  9. Logo tools

    http://www.cilogo.com/LOGO/

  10. Resize CentOS Linux hard drive partition (centos 6.3 调整LVS磁盘大小)

    查看当前磁盘信息: [root@localhost ~]# df -h 文件系统          容量  已用  可用 已用%% 挂载点/dev/mapper/VolGroup-lv_root    ...