A - The New Year: Meeting Friends

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<max(a,max(b,c)) - min(a,min(b,c)) <<endl;
return ;
}

B - Text Document Analysis

字符串暴力模拟,感觉还是需要一点技巧的,我写的太慢了。

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream> using namespace std;
const int N = ;
char a[N];
//37
//_Hello_Vasya(and_Petya)__bye_(and_OK) bool is_s(char ch) {
if (ch == '_' || ch == '(' || ch == ')' || ch == ) return true;
return false;
} int read(char str[]) {
int idx = ;
int ans = ;
while (!is_s(str[idx++])) ans++;
return ans;
} int main() {
//freopen("in.txt", "r", stdin);
int ans1 = , ans2 = , n = ;
scanf("%d", &n);
scanf("%s", a);
bool fg = false;
for (int i = ; i <= n;) {
if (a[i] == '(') fg = true;
if (a[i] == ')') fg = false;
if (is_s(a[i])) {
i++;
} else {
int tmp = read(a+i);
if (!fg) ans1 = max(ans1, tmp);
else ans2++;
i += tmp;
}
}
cout << ans1 << " " << ans2;
return ;
}

C - Polycarp at the Radio

应该也是sb暴力题,map乱搞的(队友写的==

#include <cstdio>
#include <map>
#include <queue>
using namespace std;
const int maxn = ;
map<int, int> mp;
queue<int> q;
int a[maxn], n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++) scanf("%d", &a[i]), mp[a[i]]++;
int ans = n / m;
for (int i = ; i <= m; i++) if (mp[i] < ans) q.push(i);
int cnt = ;
while (!q.empty()) {
int v = q.front(); q.pop();
for (int i = ; i <= n; i++) {
if (a[i] > m || mp[a[i]] > ans) mp[a[i]]--, a[i] = v, mp[v]++, cnt++;
if (mp[v] >= ans) break;
}
}
printf("%d %d\n", ans, cnt);
for (int i = ; i <= n; i++) printf("%d%c", a[i], i==n?'\n':' ');
return ;
}

D - Lakes in Berland

简单搜索。因为数据小,随便暴力。

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector> using namespace std;
const int N = ; char mp[N][N];
int vis[N][N], n, m, k;
int dir[][] = {, , , -, , , -, }; int dfs(int x, int y, int cnt) {
if (x < || x >= n || y < || y >= m) return -;
if (mp[x][y] == '*' || vis[x][y]) return ;
vis[x][y] = cnt;
int ans = ;
for (int i = ; i < ; ++i) {
int tmp = dfs(x+dir[i][], y+dir[i][], cnt);
if (ans != -) {
if (tmp == -) ans = -;
else ans += tmp;
}
}
return ans;
} vector<pair<int, int> > g; int main() {
while (~scanf("%d%d%d", &n, &m, &k)) {
for (int i = ; i < n; ++i) scanf("%s", mp[i]);
int cnt = , tmp, ans = ;
for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j)
if (!vis[i][j] && mp[i][j] == '.')
if ((tmp = dfs(i, j, ++cnt)) != -) g.push_back(make_pair(tmp, cnt));
sort(g.begin(), g.end());
tmp = g.size() - k;
for (int i = ; i < tmp; ++i) ans += g[i].first;
printf("%d\n", ans);
for (int k = ; k < tmp; ++k)
for (int i = ; i < n; ++i)
for (int j = ; j < m; ++j)
if (vis[i][j] == g[k].second) mp[i][j] = '*';
for (int i = ; i < n; ++i) printf("%s\n", mp[i]);
}
return ;
}

E. One-Way Reform

给一个无向图,要求把每个边都变成有向边,使尽可能多的点入度等于出度,问最多能满足多少个点,并输出每条边。(任意顺序)

感觉很厉害的一道题。

无向图存在欧拉回路的充要条件:一个无向图存在欧拉回路,当且仅当该图所有顶点度数都为偶数,且该图是连通图。
有向图存在欧拉回路的充要条件:一个有向图存在欧拉回路,所有顶点的入度等于出度且该图是连通图。

首先可以知道奇数度的点是不可能到达要求的。找出奇数度的点,两两一对连接,记做虚边,这样就可以保证每个点的度数都是偶数,那么就可以找到一条欧拉回路,保证每个点入度等于出度。

因为总度数是偶数,所以奇数度的点一定是偶数个。

如果图不连通,对每一个连通图求欧拉回路就好了。

然后输出图中非虚边就ok了。

好难想到啊= =队友花了半天给我讲明白的……然后还是WA了好多好多次(我是有多蠢啊T^T

#include <bits/stdc++.h>
using namespace std; const int N = ; struct Edge {
int next, from, to, fg; // fg: 0,2未处理 1选 -1不选
} e[N*N];
int head[N], cntE;
void addedge(int u, int v, int fg) {
e[cntE].to = v; e[cntE].from = u;
e[cntE].next = head[u]; e[cntE].fg = fg;
head[u] = cntE++;
}
int deg[N]; void dfs(int u) {
for (int i = head[u]; ~i; i = e[i].next) {
if (e[i].fg == ) {
e[i].fg = ;
e[i^].fg = -;
dfs(e[i].to);
} else if (e[i].fg == ) {
e[i].fg = e[i^].fg = -;
dfs(e[i].to);
}
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int T, n, m, u, v;
scanf("%d", &T);
while (T--) {
memset(head, -, sizeof head); cntE = ;
memset(deg, , sizeof deg);
scanf("%d%d", &n, &m);
for (int i = ; i < m; ++i) {
scanf("%d%d", &u, &v);
addedge(u, v, );
addedge(v, u, );
deg[u]++, deg[v]++;
}
int last = , odd = ;
for (int i = ; i <= n; ++i) {
if (deg[i] & ) {
++odd;
if (last) addedge(last, i, ), addedge(i, last, ), last = ;
else last = i;
}
}
for (int i = ; i <= n; ++i) dfs(i);
printf("%d\n", n - odd);
for (int i = ; i < cntE; ++i)
if (e[i].fg == ) printf("%d %d\n", e[i].from, e[i].to);
}
return ;
}

F. st-Spanning Tree

挖坑待填……

Codeforces Round #375 (Div. 2) ABCDE的更多相关文章

  1. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  3. Codeforces Round #375 (Div. 2) - D

    题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...

  4. Codeforces Round #375 (Div. 2) - C

    题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...

  5. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  6. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  7. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  8. Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树

    F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...

  9. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

随机推荐

  1. 极客编程必备的五大PHP开发应用

    有了PHP应用可以帮助编码爱好者事半功倍,提升项目质量:有了这些最新的且灵活的PHP应用使创建编码项目更加简单.便捷.本文,我们收集了五大最新的PHP开发应用. PHP应用在网络上并不多见.最重要的是 ...

  2. sqort函数用法总结

    qsort包含在<stdlib.h>头文件中,此函数根据你给的比较条件进行快速排序,通过指针移动实现排序.排序之后的结果仍然放在原数组中.使用qsort函数必须自己写一个比较函数. 函数原 ...

  3. Linux设备管理之权限倾斜——mem、proc、devfs、sysfs、udev(下)

    linux发展第一阶段 01devfs(linux2.6之前) 02udev(用户空间) 03sysfs(linux2.6之后,描述设备属性) linux发展第二阶段 01sysfs+udev(ude ...

  4. Android列表视图(List View)

    Android列表视图(ListView) ListView是一个显示滚动项列表的示视图组(viewgroup),通过使用适配器(Adapter)把这些列表项自动插入到列表中.适配器比如从一个数组或是 ...

  5. ArrayList和List之间的转换

    开发中不免碰到List与数组类型之间的相互转换,举一个简单的例子: package test.test1; import java.util.ArrayList; import java.util.L ...

  6. iOS开发:UINavigationController常用操作

    NavigationController常用操作: 更改bar的背景颜色:self.navigationController?.navigationBar.barTintColor =UIColor. ...

  7. noip2001提高组题解

    今天继续感动滚粗.第一次提交170分,不能多说. 第一题:一元三次方程 明明是寒假讲分治的时候做过的题居然还是WA而且只拿了60分,说明知识掌握实在不够牢固. 寒假做的是保留4位小数,原题只保留2位, ...

  8. mysql互为主从复制配置笔记

    MySQL-master1:192.168.72.128 MySQL-master2:192.168.72.129 OS版本:CentOS 5.4MySQL版本:5.5.9(主从复制的master和s ...

  9. <九>面向对象分析之UML核心元素之设计类,类,属性,方法,可见性

    设计类

  10. 图片鼠标滑过图片半透明(jquery特效)

    在做瑞祥之旅的过程,有一个部分是材料体系,材料体系下面.预览效果