Codeforces Beta Round #14 (Div. 2)
Codeforces Beta Round #14 (Div. 2)
http://codeforces.com/contest/14
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 */ string str[]; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
int hangmin=,hangmax=-,liemin=,liemax=-;
for(int i=;i<n;i++) cin>>str[i];
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(str[i][j]=='*'){
hangmin=min(hangmin,i);
}
}
}
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(str[i][j]=='*'){
hangmax=max(hangmax,i);
}
}
}
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(str[i][j]=='*'){
liemin=min(liemin,j);
}
}
}
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(str[i][j]=='*'){
liemax=max(liemax,j);
}
}
}
// cout<<hangmin<<" "<<hangmax<<" "<<liemin<<" "<<liemax<<endl;
for(int i=hangmin;i<=hangmax;i++){
for(int j=liemin;j<=liemax;j++){
cout<<str[i][j];
}
cout<<endl;
}
}
B
水题
#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,x;
int a[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>x;
int u,v;
for(int i=;i<=n;i++){
cin>>u>>v;
if(u>v) swap(u,v);
a[u]++,a[v+]--;
}
int ans=0x3f3f3f3f;
int num=;
for(int i=;i<=;i++){
num+=a[i];
if(num==n){
ans=min(ans,abs(i-x));
}
}
if(ans==0x3f3f3f3f) cout<<-<<endl;
else 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 */ map<pair<int,int>,int>mp;
map<pair<int,int>,int>::iterator it;
map< pair< pair<int,int>,pair<int,int> >,int >book; int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int a,b,c,d;
int flag=;
for(int i=;i<;i++){
cin>>a>>b>>c>>d;
mp[make_pair(a,b)]++;
mp[make_pair(c,d)]++;
if(a==c&&b==d) flag=;
vector<pair<int,int> >v;
v.push_back(make_pair(a,b));
v.push_back(make_pair(c,d));
sort(v.begin(),v.end());
if(book[make_pair(v[],v[])]==){
book[make_pair(v[],v[])]=;
}
else{
flag=;
}
// cout<<v[0].first<<" "<<v[0].second<<" "<<v[1].first<<" "<<v[1].second<<endl;
}
for(it=mp.begin();it!=mp.end();it++){
if(it->second!=){
flag=;
}
}
if(flag){
cout<<"NO"<<endl;
}
else{
vector<pair<int,int> >ve;
for(it=mp.begin();it!=mp.end();it++){
ve.push_back(it->first);
}
sort(ve.begin(),ve.end());
if(ve[].first==ve[].first&&ve[].first==ve[].first&&
ve[].second==ve[].second&&ve[].second==ve[].second){
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
}
} /*
0 0 0 2
2 0 2 2
0 2 0 0
2 2 2 0
*/
D
枚举删边,然后跑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 */ int n;
vector<int>ve[];
vector<pair<int,int> >d; int r; int dfs(int pos,int pre){
int len1=,len2=;
int tmp=;
for(int i=;i<ve[pos].size();i++){
if(ve[pos][i]!=pre){
tmp=max(tmp,dfs(ve[pos][i],pos));
if(r>len1){len2=len1,len1=r;}
else{len2=max(len2,r);}
}
}
tmp=max(tmp,len1+len2);
r=len1+;
return tmp;
} int main(){
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
cin>>n;
int a,b;
for(int i=;i<n;i++){
cin>>a>>b;
ve[a].push_back(b);
ve[b].push_back(a);
d.push_back(make_pair(a,b));
}
int ans=;
for(int i=;i<d.size();i++){
int t1=dfs(d[i].first,d[i].second);
int t2=dfs(d[i].second,d[i].first);
// cout<<t1<<" "<<t2<<" "<<d[i].first<<" "<<d[i].second<<endl;
ans=max(ans,t1*t2);
}
cout<<ans<<endl; }
E
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 */ ll dp[][][][];///分别表示第i个数,第j个尖峰数,尖峰高度和上升(1)或下降(0) int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,m;
for(int i=;i<;i++) dp[][][i][]=;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
for(int k=;k<=;k++){
for(int l=;l<k;l++){///更新上升的尖峰: 1:下降峰加个上升 2:上升再加一个上升
dp[i][j][k][]+=dp[i-][j-][l][]+dp[i-][j][l][];
}
if(i==){///2步不可能的情况
dp[i][j][k][]=;
}
else{
for(int l=k+;l<=;l++){
///更新下降的尖峰(1:下降峰再加一个下降,2:上升峰加一个下降)
dp[i][j][k][]+=dp[i-][j][l][]+dp[i-][j][l][];
}
}
}
}
}
cin>>n>>m;
ll ans=;
for(int i=;i<=;i++){
ans+=dp[n][m][i][];
}
cout<<ans<<endl;
}
Codeforces Beta Round #14 (Div. 2)的更多相关文章
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树形dp
D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother ...
- Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题
C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later A ...
- Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题
B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...
- Codeforces Beta Round #14 (Div. 2) A. Letter 水题
A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树的直径
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory lim ...
- Codeforces Beta Round #14 (Div. 2) Two Paths (树形DP)
Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input outp ...
- TTTTTTTTTTTTT 树的直径 Codeforces Beta Round #14 (Div. 2) D. Two Paths
tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include < ...
- 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 ...
随机推荐
- js用法
属性(attribute) function fn(){ console.log(123) } fn() var a=fn() 将函数fn()调用结果赋值给a 1.函数 ...
- 【转载】html中object标签详解
[转载自http://blog.csdn.net/soliy/archive/2010/03/22/5404183.aspx] html标签之Object标签详解 作者:网络 出处:网络 ...
- mdm9x07 ATC AT+QCFG usbnet
1 中文AT命令详解 1.1. AT+QCFG 扩展配置 AT+ QCFG 扩展配置 测试命令 AT+QCFG=? 响应 …… +QCFG: "usbnet" ...
- Oracle跨库复制表结构
1.首先建立远程连接 create public database link LINK_SJPSconnect to system identified by manager using '(DESC ...
- Ubuntu-14.04.1 desktop安装时遇到的小问题
su root认证失败:sudo passwd root,然后设置新密码. 重装linux导致g++显示已安装,但无法使用:将"系统设置"/"软件源"中所有更新 ...
- 第3章 文件I/O(7)_高级文件操作:存储映射
8. 高级文件操作:存储映射 (1)概念: 存储映射是一个磁盘文件与存储空间的一个缓存相映射,对缓存数据的读写就相应的完成了文件的读写. (2)mmap和munmap函数 头文件 #include&l ...
- 自定义ExtJS插件
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f73b6f93834c28c3933fc239045647 ...
- 3.1_分类算法之k-近邻
分类算法之k-近邻 k-近邻算法采用测量不同特征值之间的距离来进行分类 优点:精度高.对异常值不敏感.无数据输入假定 缺点:计算复杂度高.空间复杂度高 使用数据范围:数值型和标称型 一个例子弄懂k-近 ...
- python入门-函数(一)
1定义函数并且调用 注释语句""" """ def greet_user(): """显示简单的问候语&qu ...
- 记一次python爬虫实战,豆瓣电影Top250爬虫
import requests from bs4 import BeautifulSoup import re import traceback def GetHtmlText(url): for i ...