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. 魅族pro6部分应用内adb断开连接

    魅族pro6打开支付宝,adb自动断开链接,顶部有Flyme自动保护中. 进入手机管家的设置,将Flyme支付保护关掉 再次进入支付宝页面,adb不会再自动断开链接

  2. windows下查看端口被哪个进程占用

    1.netstat -anp|findstr "port" 得到进程id 2.tasklist|findstr "pid" 得到是进程名

  3. php history.back返回后表单数据丢失的解决办法

    js使用history.back返回表单数据丢失的主要原因就是使用了session_start();的原因,该函数会强制当前页面不被缓存.本文章向码农介绍php history.back返回后表单数据 ...

  4. python多重继承C3算法

    python多重继承的MRO算法选择: 经典方式.Python2.2 新式算法.Python2.3 新式算法(C3).Python 3中只保留了最后一种,即C3算法 C3算法的解析: 1.多继承UML ...

  5. python中os常用方法

    python中OS常用方法 Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问 ...

  6. 用深度学习LSTM炒股:对冲基金案例分析

    英伟达昨天一边发布“全球最大的GPU”,一边经历股价跳水20多美元,到今天发稿时间也没恢复过来.无数同学在后台问文摘菌,要不要抄一波底嘞? 今天用深度学习的序列模型预测股价已经取得了不错的效果,尤其是 ...

  7. windows CIFS sabma协议识别

    今天在linux上搭建了CIFS协议,使用sabma4.7.0版本. 通过smbstatus可以查看smb软件的版本 通过/bin/smbstatus -d 0可以查看目前正连接的客户端. 问题来了: ...

  8. IIS7根据PID查找对应的站点

    runas /user:administrator cmd cd \Windows\System32\inetsrv appcmd.exe list wp

  9. vconsole h5应用ajax请求抓包

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta co ...

  10. C关键字typedef及argc,argv,env参数含义

    C关键字typedef--为C中各种数据类型定义别名. 在此插一点C知识 int main(int argc,const char *argv[],const char *envp[])主函数的红色部 ...