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> ...
随机推荐
- CRC16-CCITT C语言代码
代码如下,使用空间换时间的方法 #define CRC16_CCITT_SEED 0xFFFF // 该位称为预置值,使用人工算法(长除法)时 需要将除数多项式先与该与职位 异或 ,才能得到最后的除数 ...
- ADOQuery.Parameters: Property Parameters does not exist
Exception class EReadError with message 'Property Parameters does not exist'. Exception class EReadE ...
- Servlet基本_Httpリクエスト、レスポンス
1.リクエスト リクエストは.リクエストライン.メッセージヘッダ.改行.メッセージボディで組まれる. 主なリクエストヘッダは. Accept クライアントが利用可能なデータメディアタイプを指定. Ac ...
- Mongodb集群节点故障恢复场景分析(转)
一个适当配置的Mongodb分片集群是没有单点故障.本文描述了分片集群中存在的几种不同的潜在的节点故障场景,以及Mongodb对这些节点故障是怎么处理的.1.Mongos节点宕机一个Mongos进程应 ...
- python实现最大重叠子串的查找
#!/usr/bin/python #查找最大重叠子串 def FindMaxDup(in_str): str_len = len(in_str) result = '' #逐级扩大搜索长度# lev ...
- html页面跳转
button <button onclick="window.location.href='edit.jsp'">完善个人信息</button> 单击提交表 ...
- python 函数返回值笔记
今天学习python时候学习到闭包和柯里化 感觉看概念时候不好理解,自己写下大概就明白点了 柯里化如下 定义一个加法函数 def add(x, y): return x + y 这是没有柯里化之前的函 ...
- 使用django实现自定义用户认证
参考资料:https://docs.djangoproject.com/en/1.10/topics/auth/customizing/ 直接拉到最后看栗子啦 django自定义用户认证(使用自 ...
- C# 监测每个方法的执行次数和占用时间(测试3)
原文:http://www.cnblogs.com/RicCC/archive/2010/03/15/castle-dynamic-proxy.html 在Nuget引用 Castle.Dynamic ...
- java的特点
java是一种跨平台.适合于分布式计算机环境的面向对象编程语言.具有以下特性:简单性.面向对象.分布性.解释性.可靠.安全.平台无关.可移植性.高性能.多线程.动态性等特点. 面向过程和面向对象可以用 ...