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 ...
随机推荐
- JSTL、EL、ONGL、Struts标签的区别与使用
一.JSTL 来源 我们使用JSP开发信息展现非常方便,也可嵌入java代码用来实现相关逻辑,但同样带来了很多问题: jsp维护难度增加 出事提示不明确,不容易提示 分工不明确等 解决上面的问题可以 ...
- STL源码中map和set中key值不能修改的实现
前言 最近正好刚刚看完,<stl源码剖析>这本书的map和set的源码部分.但是看完之后又突然发现,之前怎么没有注意到map和set容器中key不能修改是怎么实现的.故,特此整理如下. s ...
- 最大流算法(Edmons-Karp + Dinic 比较) + Ford-Fulkson 简要证明
Ford-Fulkson用EK实现:483ms #include <cstdio> #include <cstring> #define min(x,y) (x>y?y: ...
- maven常用构建命令
mvn -v 查看maven版本 compile 编译项目 install 将项目加入到本地仓库中 clean 删除target test 测试 package 打包
- POJ 1664 放苹果
放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24985 Accepted: 15908 Description ...
- 载入在线jQuery库
以百度库为例 <script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script&g ...
- MVC&WebForm对照学习:文件下载
说完了WebForm和MVC中的文件上传,就不得不说用户从服务器端下载资源了.那么今天就扯扯在WebForm和MVC中是如何实现文件下载的.说起WebForm中的文件上传,codeshark在他的博文 ...
- Android自定义的webView——可实现的网页文本的复制
package com.example.customlinearlayout.view; import android.app.ProgressDialog; import android.conte ...
- 【MySQL for Mac】在Mac终端导入&导出.sql文件
导入 打开终端输入:(前提是已经配置过MySQL环境变量) mysql -u root -p create database name; use name; source 『将.sql文件直接拖拽至终 ...
- TCP/IP详解学习笔记(2)-数据链路层
数据链路层有三个目的: 为IP模块发送和 接收IP数据报. 为ARP模块发送ARP请求和接收ARP应答. 为RARP发送RARP请 求和接收RARP应答 ip大家都听说过.至于ARP和RARP,ARP ...