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> ...
随机推荐
- Dubbo 暴露服务
1. 引入dubbo依赖 dubbo 依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId&g ...
- subprocess.Popen模块
该类用于在一个新的进程中执行一个子程序.subprocess模块底层的进程创建和管理是由Popen类来处理的. 1.subprocess.Popen的构造函数 class subprocess.Pop ...
- 跨域(二)——WebSocket
严格地说,WebSocket技术不属于HTML5,这个技术是对HTTP无状态连接的一种革新,本质就是一种持久性socket连接,在浏览器客户端通过javascript进行初始化连接后,就可以监听相关的 ...
- Haskell语言学习笔记(73)Existentials
Existentials(存在类型) Existentially quantified types(Existentially types,Existentials)是一种将一组类型归为一个类型的方式 ...
- [namespace]PHP命名空间的动态访问 & 使用技巧
----------------------------------------------------------------------------------------------- /* | ...
- js 监听浏览器刷新还是关闭事件 - 转
监听页面关闭: window.onbeforeunload = function() { //鼠标相对于用户屏幕的水平位置 - 窗口左上角相对于屏幕左上角的水平位置 = 鼠标在当前窗口上的水平位置 v ...
- C#自定义控件:如果定义控件的事件
我做了一个控件: 在控件上面添加了一个 richTextBox1 系统控件 我想要的效果时,如果点击我的控件,就执行 用户自定义的 控件的 onClick 事件 而控件的工作过程时,如果点击我的控件, ...
- hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- linux配置虚拟主机
linux 下怎么配置虚拟主机 linux 下怎么配置虚拟主机,在网上找到N个资料都是高手们随便说几句,都没怎么说清楚.问题: 我把域名(bs.jxiop.com)指向了 68.10.140.10 ...
- 构建缓存gradle
结合Kotlin使用Gradle build cache 宛丘之上兮 关注 2018.03.11 00:21* 字数 1177 阅读 505评论 5喜欢 4 在2017年4月,Gradle发布了bui ...