Codeforces Beta Round #22 (Div. 2 Only)
Codeforces Beta Round #22 (Div. 2 Only)
http://codeforces.com/contest/22
A
水题
#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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a;
vector<int>ve; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a;
ve.push_back(a);
}
sort(ve.begin(),ve.end());
ve.erase(unique(ve.begin(),ve.end()),ve.end());
if(ve.size()==) cout<<"NO"<<endl;
else cout<<ve[]<<endl; }
B
DP,有点像二维差分
#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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m;
char str[][];
int dp[][]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
scanf("%d %d",&n,&m);
int ans=;
for(int i=;i<=n;i++) scanf("%s%*c",str[i]+);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(str[i][j]==''){
dp[i][j]++;
}
dp[i][j]+=dp[i-][j]+dp[i][j-]-dp[i-][j-];
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(str[i][j]==''){
for(int k=i-;k>=;k--){
for(int l=j-;l>=;l--){
int tmp=dp[i][j]-dp[k][j]-dp[i][l]+dp[k][l];
if(!tmp){
ans=max(ans,*(i-k+j-l));
}
if(str[i][l]=='') break;
}
if(str[k][j]=='') break;
}
}
}
} cout<<ans<<endl;
}
C
构造题
#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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m,v; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m>>v;
if(m<n-||m>((n-)*(n-))/+n-) cout<<-<<endl;
else if(n<) cout<<"1 2"<<endl;
else{
int u=v-;
if(v==) u=;
for(int i = ; i <= n; i++){
if(i != v)
cout<<i<<" "<<v<<endl;
}
m -= (n - );
for(int i = ; i <= n && m; i++){
if(i == v || i == u) continue;
for(int j = i + ; j <= n && m; j++){
if(j == v || j == u) continue;
cout<<i<<" "<<j<<endl;
m--;
}
}
} }
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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n;
vector<pair<int,int> >ve;
vector<int>V; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int a,b;
for(int i=;i<=n;i++){
cin>>a>>b;
if(a>b) swap(a,b);
ve.push_back(make_pair(a,b));
}
sort(ve.begin(),ve.end());
int ans=;
int r=ve[].second;
for(int i=;i<ve.size();i++){
if(ve[i].first>r){
ans++;
V.push_back(r);
r=ve[i].second;
}
else{
r=min(r,ve[i].second);
}
}
V.push_back(r);
cout<<ans<<endl;
for(int i=;i<V.size();i++){
cout<<V[i]<<' ';
}
}
E
构造强连通分量,先找到出度为0的点,跑dfs找出链或环上的头尾节点,然后把这些节点相连即可
注意,可能存在自环,所以要判断一下
#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 maxn 500005
typedef long long ll;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ vector<int>ve[],head,last;
int d[];
int vis[]; int dfs(int pos){
vis[pos]=;
if(!vis[ve[pos][]]){
return vis[pos]=dfs(ve[pos][]);
}
return vis[pos]=pos;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int a;
for(int i=;i<=n;i++){
cin>>a;
ve[i].push_back(a);
d[a]++;
}
int k=;
for(int i=;i<=n;i++){
if(!d[i]){
k++;
head.push_back(i);
last.push_back(dfs(i));
}
}
int kk=k;
for(int i=;i<=n;i++){
if(!vis[i]){
k++;
head.push_back(i);
last.push_back(dfs(i));
}
}
if(k==&&!kk) k=;
cout<<k<<endl;
for(int i=;i<k;i++){
cout<<last[i]<<" "<<head[(i+)%k]<<endl;
}
}
Codeforces Beta Round #22 (Div. 2 Only)的更多相关文章
- 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme dfs贪心
E. Scheme To learn as soon as possible the latest news about their favourite fundamentally new ope ...
- 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> ...
随机推荐
- PHP + NGINX 控制视频文件播放,并防止文件下载
最简单的方法是使用NGINX的 internal 功能 server { listen 80; server_name www.xxx.com; location / { ...
- nginx 和 php超时设置
nginx.conf --- http节: keepalive_timeout 600; #客户端浏览器超时时间fastcgi_connect_timeout 600; #php-fpm连接超时时间 ...
- day24-抽象类与接口类
接口类 1.继承有两种用途:一:继承基类的方法,并且做出自己的改变或者扩展(代码重用) 二:声明某个子类兼容于某基类,定义一个接口类,接口类中定义了一些接口名(就是函数名)且并未实现接口的功能,子类继 ...
- FormData上传文件(不是所有的浏览器都支持)
<h1>Ajax上传文件</h1> <div> <input type="file" id="img"/> &l ...
- Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be
1.替换 compile为implementation. 2.file->invalidate caches 或者build中的clear
- MyEclipse反向生成Java代码 ,Reverse Engineering-->Java Source Folder-->没有提供任何条目
在web项目名称上,手动执行一遍Add Hibernate Capabilities,然后再去DB Browser中进行反向生成pojo实体类和hbm.xml映射文件!,具体生成反向代码的配置如下图所 ...
- 1.13.Mark1
[经济学人]双语阅读:律师事务所 标价更高 收益更少 Business 商业报道 Law firms 律师事务所 Charging more, getting less 标价更高,收益更少 L ...
- Python 字符串基本操作
字符串是Python的一种基本类型,字符串的操作包括字符串格式化输出.字符串的截取.合并,字符串的查找和替换等操作. 字符串定义 Python中有3种表示字符串的方法:单引号.双引号.三引号.引号使用 ...
- JavaScript 从定义到执行,你应该知道的那些事
JavaScript从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习JS引擎工作机制之前,我们需要引入几个相关的概念:执行环境栈.执行环境.全局对象.变量对象.活动对象.作用域和作用域链等 ...
- [PHP]PHP缓存机制之Output Control
---------------------------------------------------------------------------------------------------- ...