Codeforces_723
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的更多相关文章
随机推荐
- ChromeDriver+Selenium安装
介绍 Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作. ChromeDriver是一个Chrome浏览器驱动,用于驱动Chrome浏览器完成相应的操作 ...
- HashMap,HashTable 区别,实现原理。
HashMap是HashTable 的轻量级,非线程安全的,都是实现了map接口 区别:hashmap 允许空键值对的存在,非线程安全,效率高于hashtable,因为hashtable 是synch ...
- docker发布.net core程序的坑
docker发布遇到的两个问题 1:Could not resolve CoreCLR path. For more details, enable tracing by setting COREHO ...
- mongodb学习(二)——基本的数据操作
数据操作(重点) 数据库的核心--CRUD,增加和删除较为简单,查询和修改较复杂 查询 关系运算符 $gt 大于 $lt 小于 $gte 大于等于 $lte 小于等于 $eq | (key: valu ...
- 从操作系统层面理解Linux下的网络IO模型
I/O( INPUT OUTPUT),包括文件I/O.网络I/O. 计算机世界里的速度鄙视: 内存读数据:纳秒级别. 千兆网卡读数据:微妙级别.1微秒=1000纳秒,网卡比内存慢了千倍. 磁盘读数据: ...
- cogs 2450. 距离 树链剖分求LCA最近公共祖先 快速求树上两点距离 详细讲解 带注释!
2450. 距离 ★★ 输入文件:distance.in 输出文件:distance.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 在一个村子里有N个房子,一 ...
- max_element( )
直接用这个函数 , 会比自己写个for 判断快的多了 . position=max_element(a,a+n)-a; position 代表找到最大元素的位置 , max_element( ) 的 ...
- fill 的用法
博客 : http://blog.csdn.net/liuchuo/article/details/52296646 fill函数的作用是:将一个区间的元素都赋予val值.函数参数:fill(vec. ...
- 用PHP写下HELLO WORLD!
一.选择PHP开发工具 1.phpstorm最新版本 2.打开phpstorm界面 按create键,选择new window ,出下如下页面: 鼠标放在文件夹上,右键单击,弹出以下对话框:做如下操作 ...
- 盘它!!一步到位,Tensorflow 2的实战 !!LSTM下的股票预测(附详尽代码及数据集)
关键词:tensorflow2.LSTM.时间序列.股票预测 Tensorflow 2.0发布已经有一段时间了,各种新API的确简单易用,除了官方文档以外能够找到的学习资料也很多,但是大都没有给出实战 ...