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. 机器学习实战之朴素贝叶斯进行文档分类(Python 代码版)

    贝叶斯是搞概率论的.学术圈上有个贝叶斯学派.看起来吊吊的.关于贝叶斯是个啥网上有很多资料.想必读者基本都明了.我这里只简单概括下:贝叶斯分类其实就是基于先验概率的基础上的一种分类法,核心公式就是条件概 ...

  2. (已解决)java.lang.NoSuchMethodException: com.kevenwu.pojo.User.<init>()

    搭建ssm框架时报了如下错误,原因是: mybatis在初始化bean的时候需要无参构造器, 如果写了有参构造器,将会把无参构造器覆盖掉,加上一个无参构造器就可以了

  3. echarts图表--统计图表

    echarts官网图表API:http://echarts.baidu.com/index.html

  4. 使用ubuntu远程连接windows, Connect to a Windows PC from Ubuntu via Remote Desktop Connection

    from: https://www.digitalcitizen.life/connecting-windows-remote-desktop-ubuntu NOTE: This tutorial w ...

  5. mysql主从复制搭建中几种log和pos详解

    一.主从原理 Replication 线程   Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql in ...

  6. eclipse打断点,进行弹窗提示后点击是才进入debug视图,这个要怎么恢复

    window --> preferences --> Run/Debug --> Perspectives 里的 open the associated perspective wh ...

  7. C语言中插入汇编nop指令

    工作过程中,有的时候需要打桩cycle,想在C语言中插入nop指令,可以采取的方法是 头文件中加入#inlude <stdio.h> 定义一个内联函数,然后调用这个函数,不过得测一下平台调 ...

  8. 免費查看SQL PLAN的工具 - SQL Sentry Plan Explorer

    今天 Terry大 介紹給小弟這個 SQL Sentry Plan Explorer 工具,可以用來看SQL Plan. 什麼? 用SSMS看不就很清楚了嗎? 這個Tool有把SQL Plan幫我們整 ...

  9. [PC]PHPCMS v9.5.6整合UEditer1.4.2

    ----------------------------------------------------------------------------------------------- 首先去U ...

  10. ArcGIS案例学习笔记3_1_地理配准案例_目视找点

    ArcGIS案例学习笔记3_1_地理配准案例_目视找点 计划时间:第3天上午 方法:地理配准/添加链接点/左键/右键/输入坐标 数据:江苏省.zip 矢量:省界,市界,GPS WGS84 地理坐标系 ...