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)的更多相关文章

  1. 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 ...

  2. Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题

    C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later A ...

  3. Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题

    B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...

  4. 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. ...

  5. 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 ...

  6. 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 ...

  7. TTTTTTTTTTTTT 树的直径 Codeforces Beta Round #14 (Div. 2) D. Two Paths

    tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include < ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. Response、Request、QueryString,修改,Cookies

    Response对象:响应请求Response.Write("<script>alert('添加成功!')</script>");Response.Redi ...

  2. [转] oracle 数据库 SQL plus 连接方法

    http://hi.baidu.com/zzy382/item/a5b197f97a38e01ba7298832 之前电脑上安装了一个 Oracle  有一段时间没用,就把密码给忘了,按上面链接里的操 ...

  3. windows 网管常用命令

    Windows网络命令行程序 这部分包括: 使用 ipconfig /all 查看配置 使用 ipconfig /renew 刷新配置 使用 ipconfig 管理 DNS 和 DHCP 类别 ID ...

  4. [转载]tornado.database添加PooledDB连接池功能

    转载自 http://chenxiaoyu.org/2009/12/01/python-tornado-dbutil.html tornado.database模块简单包装了下对MySQL的操作,短小 ...

  5. 慕课网价值149《前端JavaScript面试技巧》笔记大公开——适应群体(学生或应届毕业生)

    1.基础知识(一) http://note.youdao.com/noteshare?id=b81f56399b01da0ab5e870ea612ab94b&sub=B8ECBC1B57154 ...

  6. http协议和https协议

    内容: 1.http协议介绍 2.https协议介绍 3.http协议和https协议对比 1.http协议介绍 (1)http协议是什么 1 一个传输协议,协议就是双方都遵守的规范. 2 为什么叫超 ...

  7. PHP笔记(配置UPUPW环境)

    一,首先修改HOSTS将127.0.0.1 gzt.com加入,前面不要# 二,GZT.COM的数据库文件在--------------配置在: - 三,配置 主要修改这几个  $BASIC=arra ...

  8. python补充2

    一 关于类中的self以及继承问题 请看下面一段代码 class Base: def f1(self): self.f2() def f2(self): print('...') class Foo( ...

  9. 26. 天马tomcat授权文件的影响因素

    问题:Tianma版本同一台机器的Server端序列号有时会显示空白 描述:同一台机器的tomcat,tianma版本序列号为空(如图) 解决:手动删除ABS_DOCUMENT\LiveBos目录下s ...

  10. 4. java乱码处理

    //返回到jsp页面 //request.setCharacterEncoding("utf-8"); //response.setContentType("text/h ...