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程序员的40点陋习

    1.不写注释 2.不使用可以提高生产效率的IDE工具 3.不使用版本控制 4.不按照编程规范写代码 5.不使用统一的方法 6.编码前不去思考和计划 7.在执行sql前不执行编码和安全检测 8.不使用测 ...

  2. Android权限安全(11)内置计费相关安全要点

    内置计费相关安全要点 1.计费Server接口保密且Transiction 加密 (SSL) 2.仅允许配套的安全本地组件(通常是第三方付费sdk如支付宝)与计费Server通信,且安全本地组件负责与 ...

  3. 对github中项目进行更新

    进入本地仓库文件夹,我的仓库名是tufujiegit,然后 进入 git  clone  接着将先前记录下来的地址复制到后面,回车 将下载github中该仓库的所有文件及文件夹,包括.git文件夹在内 ...

  4. HNOI2002营业额统计(平衡树)

    标准的平衡树. 贴个splay吧 var v,l,r,fa:..] of longint; root,x,i,n,ans:longint; procedure zig(x:longint); var ...

  5. ASP.NET MVC @helper使用说明

    简单的 @helper 方法应用场景 Razor中的@helper语法让您能够轻松创建可重用的方法,此方法可以在您的视图模板中封装输出功能.他们使代码能更好地重用,也使代码更具有可读性. 在我们定义@ ...

  6. 移动APP服务端API设计应该考虑到的问题

    2014年,移动APP的热度丝毫没有减退,并没有像桌面软件被WEB网站那样所取代, 不但如此,越来越多的传统应用.网站也都开始制作自己的移动APP,也就是我们常说的IOS客户端.android客户端. ...

  7. Java [Leetcode 119]Pascal's Triangle II

    题目描述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...

  8. 持有对象:总结JAVA中的常用容器和迭代器,随机数 速查

    JAVA使用术语“Collection”来指代那些表示集合的对象,JAVA提供的接口很多,首先我们先来记住他们的层次结构: java集合框架的基本接口/类层次结构 java.util.Collecti ...

  9. 【转】u盘不显示盘符

    转自http://jingyan.baidu.com/article/f3ad7d0fd0793e09c3345b31.html 我的情况: 电脑只有一个c盘,插入u盘,u盘的盘符为d. 弹出u盘,但 ...

  10. Hadoop集群中Hbase的介绍、安装、使用

    导读 HBase – Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. 一.Hbase ...