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. IO 和 NIO 的区别

    IO:阻塞IO,面向流:当一个线程调用read() 或 write()时,该线程被阻塞,直到有一些数据被读取,或数据完全写入,该线程在此期间不能再干任何事情了:可以有少量的连接使用非常高的带宽,一次发 ...

  2. 【版本发布】JAVA微服务开发框架,Jeecg-P3 1.0.0 重构版本发布

    1.项目介绍 Jeecg-P3是一个微服务框架,采用插件式模式开发:业务插件以JAR方式提供,松耦合可插拔支持独立部署,也可无缝集成Jeecg平台中,目前jeecg已经提供了在线聊天,我的邮箱等一系列 ...

  3. day01-MySQL介绍

    一.MySQL的介绍 1.1.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 W ...

  4. JVM jstack 详解

    https://blog.csdn.net/zxp_cpinfo/article/details/54971115 输出到文件 >jstack -l PID >> /root/123 ...

  5. Others-大数据平台Lambda架构浅析(全量计算+增量计算)

    大数据平台Lambda架构浅析(全量计算+增量计算) 2016年12月23日 22:50:53 scuter_victor 阅读数:1642 标签: spark大数据lambda 更多 个人分类: 造 ...

  6. Servlet基本_クッキー、URLリライティング

    1.クッキーの基礎クッキーは.クライアント側に保存されるテキストデータです. セキュリティ上の制約.・自分で発行したクッキーにしかアクセスできない.クッキーには発行元のホストの情報が記録されている.・ ...

  7. 转: CSS3 @media 用法总结

    一.首先是<meta>标签 <meta name="viewport" content="width=device-width, initial-sca ...

  8. [原创]HTML 用div模拟select下拉框

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML xmlns=" ...

  9. delphi删除整个目录及目录下的文件

    //删除整个文件夹及其下的所有文件function DelDirAll(aDir: string): Boolean; var vSearch: TSearchRec; vRet: integer; ...

  10. week5 0.1 安装materializecss

    用ATOM打开项目 App是什么呢?就是App.js 我们将不需要的删掉 用一下materialize(类似bootstrap的东西) 官网https://materializecss.com/ 想用 ...