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> ...
随机推荐
- Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
在Tomcat的server.xml中配置两个context,出现其中一个不能正常启动,交换配置顺序,另一个又不能正常启动,即始终只有第二个配置能启动的情况.如果单独部署,都没有问题.报错大致内容如下 ...
- alias 设置别名
我们在使用Linux中使用较长的命令而且要经常要使用时,总是会使用别名,这里就简单的介绍一下别名alias 指令:alias设置指令的别名 语法:# alias name='command line ...
- 多媒体基础知识之PCM数据《 转》
多媒体基础知识之PCM数据 1.什么是PCM音频数据 PCM(Pulse Code Modulation)也被称为脉冲编码调制.PCM音频数据是未经压缩的音频采样数据裸流,它是由模拟信号经过采样.量化 ...
- git安装与基本命令
一.前言 GibHub的名字源于Git,Git是一个分布式版本控制系统,让程序员团队能够协作开发项目,Git帮助大家管理为项目所做的工作,避免一个人所做的修改影响其他人所做的修改.你在项目中实现一个新 ...
- python import package at different path
1.导入上一级目录的package import sys sys.path.append('..') import <package> # import package at ../ 2. ...
- 4.Python文件操作
文件内需要写入的内容 Seems the love I’ve ever known 看来,过去我所知道的爱情 Has always been the most destructive kind 似乎总 ...
- harbor仓库镜像的删除
harbor仓库镜像的删除 刚开始自己摸索了下,直接webui界面删除后,发现仓库空间未释放 上传之前仓库空间占用为 上传之后仓库空间占用为 在webui界面上删除镜像后 查看大小 依旧为286m,到 ...
- C++随记
1.const限定符 const限定变量的值不可变,并且const对象必须要初始化 const int buf = 512; //正确,表明buf的值为512 buf = 400; //错误,buf ...
- splunk + docker-compose 实现自定义 index
splunk是一款非常优秀的运维管理平台.Splunk 是机器数据的引擎.使用 Splunk 可收集.索引和利用所有应用程序.服务器和设备生成的快速移动型计算机数据 . 使用 Splunking 处理 ...
- 分页插件 PageHelper
一步:pom 依赖 二步:controller层 三步:id调用了三个包,org.n3r.idworker的包,这是一体的不用修改,调用即可生成,电商,腾讯都会用这个 , 前三位是年日 四步:serv ...