Codeforces Round #375 (Div. 2) ABCDE
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 ;
}
字符串暴力模拟,感觉还是需要一点技巧的,我写的太慢了。
#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 ;
}
应该也是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 ;
}
简单搜索。因为数据小,随便暴力。
#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 ;
}
给一个无向图,要求把每个边都变成有向边,使尽可能多的点入度等于出度,问最多能满足多少个点,并输出每条边。(任意顺序)
感觉很厉害的一道题。
首先可以知道奇数度的点是不可能到达要求的。找出奇数度的点,两两一对连接,记做虚边,这样就可以保证每个点的度数都是偶数,那么就可以找到一条欧拉回路,保证每个点入度等于出度。
因为总度数是偶数,所以奇数度的点一定是偶数个。
如果图不连通,对每一个连通图求欧拉回路就好了。
然后输出图中非虚边就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 ;
}
挖坑待填……
Codeforces Round #375 (Div. 2) ABCDE的更多相关文章
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #375 (Div. 2) - D
题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...
- Codeforces Round #375 (Div. 2) - C
题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...
- Codeforces Round #375 (Div. 2) - B
题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...
- Codeforces Round #375 (Div. 2) - A
题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...
- Codeforces Round #460 (Div. 2) ABCDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...
- 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 ...
- 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 ...
随机推荐
- 用matlab训练数字分类的深度神经网络Training a Deep Neural Network for Digit Classification
This example shows how to use Neural Network Toolbox™ to train a deep neural network to classify ima ...
- iosUITextField属性
@property UITextField *caption; caption = [[UITextField alloc] initWithFrame:CGRectMake(, self.frame ...
- shell bash判断文件或文件夹是否存在
#shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...
- iOS学习笔记: 使用CAShapeLayer创建带有空心区域的遮罩层
CAShapeLayer是用来接受矢量Path,直接使用GPU来进行渲染的特殊图层.看下面效果: 对应代码: let markLayer = CAShapeLayer(); markLayer.fra ...
- 对github中项目进行更新
进入本地仓库文件夹,我的仓库名是tufujiegit,然后 进入 git clone 接着将先前记录下来的地址复制到后面,回车 将下载github中该仓库的所有文件及文件夹,包括.git文件夹在内 ...
- 转:java提取图片中的像素
本文转自:http://www.infosys.tuwien.ac.at/teaching/courses/WebEngineering/References/java/docs/api/java/a ...
- 信息:Could not publish server configuration for Tomcat v6.0 Server at localhost. Multiple Context
需要把server.xml更正一下,去掉重复的context.或者把整个server文件夹都删掉,重新添加服务器.也可以在server窗口中删除server,再新添加一个server.
- Web网站的性能测试工具
随着Web 2.0技术的迅速发展,许多公司都开发了一些基于Web的网站服务,通常在设计开发Web应用系统的时候很难模拟出大量用户同时访问系统的实际情况,因此,当Web网站遇到访问高峰时,容易发生服务器 ...
- Android+Eclipse+Java:在“正在启动 CrazySnake”期间发生了内部错误, java.lang.NullPointerException
删除工作空间下的.metadata 文件夹 重启 Eclipse 清理工作空间
- HelloX操作系统网络功能简介及使用和开发指南
HelloX网络功能简介及使用和开发指南 HelloX网络功能简介 作为物联网操作系统,网络功能是必备的核心功能之一.按照规划,HelloX实现了两个不同类型的TCP/IP协议栈,一个面向资源受限的嵌 ...