Codeforces Beta Round #35 (Div. 2)
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)的更多相关文章
- Codeforces Beta Round #35 (Div. 2) E. Parade(扫描线)
题目链接 只要会做,周长并,这题肯定有思路. 有个小地方敲错了,细心啊,扫描线,有一段时间没写过了,还有注意排序的问题,很重要. #include <iostream> #include ...
- Codeforces Beta Round #18 (Div. 2 Only)
Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- 为什么我希望用C而不是C++来实现ZeroMQ
原文在这里 开始前我要先做个澄清:这篇文章同Linus Torvalds这种死忠C程序员吐槽C++的观点是不同的.在我的整个职业生涯里我都在使用C++,而且现在C++依然是我做大多数项目时的首选编程语 ...
- day30-模块和包
一.模块介绍 1.什么是模块 在python中,一个函数封装一个功能,当一个文件中包含很多个函数,而我们在其他程序中经常会用到这个文件中的功能时,那么我们就可以将这个包含多个函数的文件封装成一个模块, ...
- Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
在Tomcat的server.xml中配置两个context,出现其中一个不能正常启动,交换配置顺序,另一个又不能正常启动,即始终只有第二个配置能启动的情况.如果单独部署,都没有问题.报错大致内容如下 ...
- Servlet基本_クッキー、URLリライティング
1.クッキーの基礎クッキーは.クライアント側に保存されるテキストデータです. セキュリティ上の制約.・自分で発行したクッキーにしかアクセスできない.クッキーには発行元のホストの情報が記録されている.・ ...
- 好玩的Raft动画演示,原理秒懂
关于Raft原理,许多朋友也许不是很明白原理,下面的地址是一个好玩的Raft动画,看完后能够很快的掌握Raft原理: http://thesecretlivesofdata.com/raft/ 动画中 ...
- SQL Server 中系统视图sysobjects中type字段的说明
对象类型: AF = 聚合函数 (CLR) C = CHECK 约束 D = DEFAULT(约束或独立) F = FOREIGN KEY 约束 FN = SQL 标量函数 FS = 程序集 (CLR ...
- centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod
centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod ...
- html兼容手机浏览器
其实主要就是改掉HTML页面声明: 在网页中加入以下代码,就可以正常显示了: <meta name="viewport" content="width=device ...
- 16.1 用auth0服务 实现用登录和管理 使用auth版本的2个大坑。
这是三周内容,实现用户登录和管理 回到master分支 切换到 han分支 更新一下 然后工作 开始工作写代码了 安装2个angular端的auth0的lib,也可不安装,后边有不安装的做法 不安装的 ...
- unity 2048Game
将游戏分为四个脚本,将数据和界面分开,这是开发模式常用的类似于mvc模式,但由于我们只用一个二位数组就可以保存数据,所以讲m省略 GameControllor 控制游戏数据的脚本, using Uni ...