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. nginx 根据域名和地址跳转

    设置nginx变量 set $domail_url "$host$request_uri"; 判断并重定向if ($domail_url = '123.com/about/'){  ...

  2. 修改页面中显示出需要修改的数据(包括select选择框复显示)

    页面中需要用到某个对象时,在底层代码中赋值,然后页面用java代码进行获取调用 如下截图: select复显示:根据后台方法赋值选择框 ,并设置初始值 按钮及选择框的禁用(五种方法): 方法一: $( ...

  3. pycharm 直接删掉数据表之后,makemigration和migrate 之后,数据库中依然没有生成数据表的问题

    综合分析一下行程这个问题的原因: 在终端中运行 select * from django_migrations; 查看 提交的记录,如果你的表删掉了,记录还在,那么数据库会觉得,这个表依然是存在的,所 ...

  4. Linux:客户端的实现

    写了一个简单的服务器软件,但是没有写客户端.现在我将客户端实现了,其实昨天已经说了客户端的实现步骤了. 步骤: socket() 初始化 connet()链接 从标准输入读数据fgets() 传数据到 ...

  5. JSON数据的解析和生成(Swift)

    Codable public typealias Codable = Decodable & Encodable public protocol Decodable {} public pro ...

  6. 国内Maven仓库 - 2018年5月2日15:54:10

    <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...

  7. MongoDB分布式集群搭建

    最近在做一个关于车险的项目,由于数据量较大,实验室的Boss决定采用HBase+ES/MongoDB这两种方案,并做性能对比,本人负责MongoDB方案.为了满足海量数据的存储要求,需要搭建一个分布式 ...

  8. hdu1215-七夕节-(埃氏筛+唯一分解定理)

    七夕节 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  9. css3选择器补充

    一.关系选择器 1.E+F   (E元素下一个满足条件的兄弟元素节点) <style> div + p{ background-color:red;// 第一个p元素变色 } </s ...

  10. Oracle11g服务详细介绍

    Oracle11g服务详细介绍及哪些服务是必须开启的? Oracle ORCL VSS Writer Service Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Se ...