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. Appium录制脚本520-2

    1.录制自动化脚本 场景:启动雪球,点击我的,登陆雪球,选择手机及其他登陆,输入手机号 2.使用Java进行测试Appium测试 2.1创建Java工程 file-创建maven工程-填写GroupI ...

  2. 第13章 TCP编程(3)_基于自定义协议的多进程模型

    5. 自定义协议编程 (1)自定义协议:MSG //自定义的协议(TLV:Type length Value) typedef struct{ //协议头部 ];//TLV中的T unsigned i ...

  3. 文件读写’r'和’rb’区别

    2012年08月22日 ⁄ 综合 ⁄ 共 849字 ⁄ 字号 小 中 大 ⁄ 评论关闭不管何种语言在进行文件读写时,大家都知道有以下模式: r,rb,w,wb 那么在读写文件时,有无b标识的的主要区别 ...

  4. Spring学习之AOP详解

    aop使用方式 @Aspect注解 wildcards通配符: * 匹配任意数量的字符 + 匹配指定类及其子类 .. 一般用于匹配任意数的子包或参数 operators运算符 && 与 ...

  5. selenium+python自动化94-行为事件(ActionChains)源码详解

    ActionChains简介 actionchains是selenium里面专门处理鼠标相关的操作如:鼠标移动,鼠标按钮操作,按键和上下文菜单(鼠标右键)交互. 这对于做更复杂的动作非常有用,比如悬停 ...

  6. openStack虚拟机error 错误状态基于差异镜像+基镜像做恢复

  7. ASP.NET CMS: Administration Template

    ASP.NET CMS: Administration Template For many creating advanced ASP.NET website or application admin ...

  8. Java 权限框架 Shiro 实战二:与spring集成、filter机制

    转自:https://www.cnblogs.com/digdeep/archive/2015/07/04/4620471.html Shiro和Spring的集成,涉及到很多相关的配置,涉及到shi ...

  9. sts安装出现could not find jar:file解决办法

    转自:https://blog.csdn.net/weixin_43702329/article/details/84823912 标题sts插件下载好但是安装出错 我的eclipse是4.5.2,在 ...

  10. PowerDesigner 连接oracle数据库

    TNS Service Name 不是监听名称,填写这个格式就可以了 10.0.0.2:1521/orcl