A.取中间那个点即可。

#include<bits/stdc++.h>
using namespace std; int a[]; int main()
{
ios::sync_with_stdio(false);
cin >> a[] >> a[] >> a[];
sort(a,a+);
cout << a[]-a[] << endl;
return ;
}

B.模拟,注意判断是否在括号内。

#include<bits/stdc++.h>
using namespace std; int n;
string s; int main()
{
cin >> n;
getchar();
getline(cin,s);
int maxx = ,cnt = ,now = ,flag = ;
for(int i = ;i < n;i++)
{
if(s[i] == '(')
{
flag = ;
now = ;
}
else if(s[i] == ')')
{
flag = ;
if(now) cnt++;
now = ;
}
else if(s[i] == '_')
{
if(flag == && now) cnt++;
now = ;
}
else
{
now++;
if(flag == ) maxx = max(maxx,now);
}
}
cout << maxx << " " << cnt << endl;
return ;
}

C.先算出ans,再把个数不到ans的数填满。

#include<bits/stdc++.h>
using namespace std; int n,m,a[],b[] = {}; int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = ;i <= n;i++)
{
cin >> a[i];
if(a[i] <= m) b[a[i]]++;
}
int ans = n/m,cnt = ,now = ;
for(int i = ;i <= n;i++)
{
if(a[i] <= m && b[a[i]] <= ans) continue;
while(b[now] >= ans) now++;
if(now == m+) break;
if(a[i] <= m) b[a[i]]--;
a[i] = now;
b[now]++;
cnt++;
}
cout << ans << " " << cnt << endl;
for(int i = ;i <= n;i++) cout << a[i] << " ";
cout << endl;
return ;
}

D.dfs找出每一个湖泊,按面积排序,把cnt-k个小的填满。

#include<bits/stdc++.h>
using namespace std; int n,m,k,vis[][] = {},ok,sum;
int dx[] = {,,-,};
int dy[] = {-,,,};
string s[];
struct xxx
{
int x,y,sum;
friend bool operator <(xxx a,xxx b)
{
return a.sum < b.sum;
}
}a[]; void dfs1(int x,int y)
{
if(vis[x][y]) return;
vis[x][y] = ;
sum++;
for(int i = ;i < ;i++)
{
int xx = x+dx[i],yy = y+dy[i];
if(xx < || xx > n || yy < || yy > m)
{
ok = ;
continue;
}
if(s[xx][yy] == '*') continue;
dfs1(xx,yy);
}
} void dfs2(int x,int y)
{
s[x][y] = '*';
for(int i = ;i < ;i++)
{
int xx = x+dx[i],yy = y+dy[i];
if(xx < || xx > n || yy < || yy > m || s[xx][yy] == '*') continue;
dfs2(xx,yy);
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m >> k;
int cnt = ;
for(int i = ;i <= n;i++)
{
cin >> s[i];
s[i] = " "+s[i];
}
for(int i = ;i <= n;i++)
{
for(int j = ;j <= m;j++)
{
if(s[i][j] == '*' || vis[i][j]) continue;
ok = ;
sum = ;
dfs1(i,j);
if(ok)
{
a[++cnt].x = i;
a[cnt].y = j;
a[cnt].sum = sum;
}
}
}
sort(a+,a++cnt);
cnt -= k;
int ans = ;
for(int i = ;i <= cnt;i++)
{
ans += a[i].sum;
dfs2(a[i].x,a[i].y);
}
cout << ans << endl;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= m;j++) cout << s[i][j];
cout << endl;
}
return ;
}

E.因为是无向图,所以有偶数个度为奇数的点,我们把他们与第n+1个点相连,则所有点的度都是偶数个,存在欧拉回路,输出这个回路的路径(不包括第n+1个点),符合要求。

#include<bits/stdc++.h>
using namespace std; int n,m,d[];
set<int> s[]; void dfs(int now)
{
while(s[now].size())
{
int t = *s[now].begin();
s[now].erase(t);
s[t].erase(now);
if(now != n+ && t != n+) cout << now << " " << t << endl;
dfs(t);
}
} int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n >> m;
memset(d,,sizeof(d));
while(m--)
{
int x,y;
cin >> x >> y;
s[x].insert(y);
s[y].insert(x);
d[x]++;
d[y]++;
}
int ans = ;
for(int i = ;i <= n;i++)
{
if(d[i]%)
{
s[i].insert(n+);
s[n+].insert(i);
}
else ans++;
}
cout << ans << endl;
for(int i = ;i <= n;i++) dfs(i);
}
return ;
}

F.原图无向连通,可以把原图的除s,t外的点分为三类团。

①与s相连。②与t相连。③与s,t相连。

若不存在第③类团,则把相应团与s或t相连,最后把s与t相连。

若存在第③类团,则s与t不必相连,可以通过第③类团来把他们相连,这样其中某个点的度就少了1,为最优情况。

#include<bits/stdc++.h>
using namespace std; struct xx
{
int x,y;
xx(int a,int b):x(a),y(b){};
};
int n,m,x,y,dx,dy,cnt = ,a[] = {},b[] = {},vis[] = {};
vector<int> v[];
vector<xx> ans; void dfs(int now)
{
vis[now] = ;
for(int i = ;i < v[now].size();i++)
{
int t = v[now][i];
if(t == x) a[cnt] = now;
else if(t == y) b[cnt] = now;
else if(!vis[t])
{
ans.push_back(xx(now,t));
dfs(t);
}
}
} int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = ;i <= m;i++)
{
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> x >> y >> dx >> dy;
for(int i = ;i <= n;i++)
{
if(vis[i] || i == x || i == y) continue;
++cnt;
dfs(i);
}
int z = ;
for(int i = ;i <= cnt;i++)
{
if(a[i] == )
{
ans.push_back(xx(b[i],y));
dy--;
}
else if(b[i] == )
{
ans.push_back(xx(a[i],x));
dx--;
}
else z++;
}
if(dx < || dy < || dx+dy- < z)
{
cout << "No" << endl;
return ;
}
if(z == ) ans.push_back(xx(x,y));
else
{
int flag = ;
for(int i = ;i <= cnt;i++)
{
if(a[i] == || b[i] == ) continue;
if(flag)
{
if(dx)
{
ans.push_back(xx(a[i],x));
dx--;
}
else
{
ans.push_back(xx(b[i],y));
dy--;
}
}
else
{
flag = ;
ans.push_back(xx(a[i],x));
dx--;
ans.push_back(xx(b[i],y));
dy--;
}
}
}
cout << "Yes" << endl;
for(int i = ;i < ans.size();i++) cout << ans[i].x << " " << ans[i].y << endl;
return ;
}

Codeforces_723的更多相关文章

随机推荐

  1. Android系统启动过程分析

    Android系统启动过程分析 一.Android平台架构 首先贴一张Android系统架构图方便理解整个Android架构,这可以让我们从整体上对整个启动流程有个大概认知. 可以看出整个架构由5部分 ...

  2. 【Java基础总结】网络编程

    网络编程 InetAddress tcp udp

  3. 【转】8 个效果惊人的 WebGL/JavaScript 演示

    英文原文:9 IMPRESSIVE WEBGL JAVASCRIPT EFFECT SHOWCASE,翻译:iteye WebGL 是一种 3D 绘图标准,这种绘图技术标准允许把 JavaScript ...

  4. 七牛云上传视频并截取第一帧为图片(js实现)

    本文出自APICloud官方论坛, 感谢论坛版主 东冥羽的分享. 七牛云上传视频并截取第一帧作为视频的封面图. 使用js上传,模块videoPlayer截取第一帧(有专门的截图模块,但是我使用的有点问 ...

  5. 一起来学习XPATH,来看看除了正则表达式我们还能怎么抓取数据

    参考学习的网站链接http://www.w3school.com.cn/xpath/xpath_intro.asp 首先理清楚一些常识 以此为例 <?xml version="1.0& ...

  6. Activiti CamelTask(骆驼任务)

    Activiti CamelTask(骆驼任务) 作者:Jesai 人生想讲个不成熟的建议 前言: Camel任务可以从Camel发送和介绍消息,由此强化了activiti的集成功能. 注意camel ...

  7. 【转载】Notepad++源码分析

    在网上发现了一个哥们写了关于Notepad++源码的文章,不过就写了一就没有了,我就接着他的工作再说说吧! 大三了,也写了一点儿程序了,但是如果只是按照自己的思路写下去恐怕难以提高,于是准备开始阅读一 ...

  8. 重写ThreadFactory方法和拒绝策略

    最近项目中要用到多线程处理任务,自然就用到了ThreadPoolTaskExecutor这个对象,这个是spring对于Java的concurrent包下的ThreadPoolExecutor类的封装 ...

  9. python模拟鼠标拖动操作的方法

    本文实例讲述了python模拟鼠标拖动操作的方法.分享给大家供大家参考.具体如下: pdf中的书签只有页码,准备把现有书签拖到一个目录中,然后添加自己页签.重复的拖动工作实在无趣,还是让程序帮我实现吧 ...

  10. Ubuntu16手动安装OpenStack

    记录大佬的博客全文转载于https://www.voidking.com/dev-ubuntu16-manual-openstack-env/ 前言 <Ubuntu16安装OpenStack&g ...