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> ...
随机推荐
- linux输入密码的实现
可以使用 getpass 这个函数,无回显的密码,为什么无回显,因为Linux的开发者一般认为不回显比显示为*更安全(比如当密码只有一两位长度的时候,设置为*几乎没有一点安全性). char *get ...
- win10 死机 无响应
win10 死机 无响应 用着用着无响应,结束任务出不来,ctrl+alt+delete 无效. 点 窗口的关闭关闭不了. 鼠标键盘无响应. 写的代码变成乱码,影响太严重了,损失惨重. 紧急启动 c ...
- centos7 自动定时备份mysql数据库
shell脚本:mysqlbak.sh #!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbinexpo ...
- WDA-Webdynpro应用发布至EP
主要是记录下Webdynpro应用发布到EP端的整个操作过程. 1.系统管理System Administration 定义与后台应用系统R3的连接 1.1设置连接参数 路径:System Admin ...
- oracle 修改字符集 为ZHS16GBK
一.oracle server 端 字符集查询 select userenv('language') from dual 其中NLS_CHARACTERSET 为server端字符集 NLS_LANG ...
- EventBus 源码学习
打开一看,原来相关代码并不多,下面看下细节 主要方法也就是注册,取消注册和发送事件,可以看到两个主要的变量就是subscribers和dispatcher public void register(O ...
- ref与out
注意点: ref和out都是按地址传递,使用后都将改变原来参数的数值 方法定义和调用方法都必须显式使用 ref/out 关键字 ref: 作为ref参数传递的变量在方法调用中传递之前必须初始化 out ...
- linux 覆盖可执行文件的问题
测试环境是3.10.0 内核. 有一次操作中,发现cp -f A B执行的时候,行为不一样: 当B没被打开,则正常覆盖B. 当B是被打开,但没有被执行,则能覆盖, 当B被打开,且被执行,则不能直接覆盖 ...
- 【386】operator 的 itemgetter、slice、and_、or_
itemgetter 用来获取数组中指定索引的元素 from operator import itemgetter itemgetter(1, 3, 5)('ABCDEFG') output: ('B ...
- 关于HashMap多线程下环形链表的总结
目录 1. 概述 2. 敲黑板的点 3. 为什么会出现循环链表的情况呢?(jdk1.7) 4. jdk1.8中改进了resize方法 5. HashMap的线程安全问题 6. 总结 1. 概述 本文主 ...