Codeforces Round #375 (Div. 2) ABCDE

时间:2022-06-15 04:38:02

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 &num;261 &lpar;Div&period; 2&rpar;&lbrack;ABCDE&rsqb;

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

  2. Codeforces Round &num;279 &lpar;Div&period; 2&rpar; ABCDE

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

  3. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; - D

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

  4. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; - C

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

  5. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; - B

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

  6. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; - A

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

  7. Codeforces Round &num;460 &lpar;Div&period; 2&rpar; ABCDE题解

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

  8. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; F&period; st-Spanning Tree 生成树

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

  9. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; E&period; One-Way Reform 欧拉路径

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

随机推荐

  1. Codeforces Round &num;293 &lpar;Div&period; 2&rpar;

    A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...

  2. 【模拟,时针分针秒针两两夹角】【没有跳坑好兴奋】hdu - 5387 (多校&num;8 1008)

    算是最好写的一道题了吧,最近模拟没手感,一次过也是很鸡冻o(* ̄▽ ̄*)o 注意事项都在代码里,没有跳坑也不清楚坑点在哪~ #include<cstdio> #include<cst ...

  3. Fundamental Datastructure

    11988 - Broken Keyboard (a.k.a. Beiju Text) 可以用deque来模拟. #include <iostream> #include <stri ...

  4. latch和DFF的区别和联系

    1.latch的缺点 ①没有时钟端,不受系统同步时钟的控制,无法实现同步操作:和当前我们尽可能采用时序电路的设计思路不符. ②对输入电平敏感,受布线延迟影响较大,很难保证输出没有毛刺产生: ③latc ...

  5. Lenovo Y430P安装Linux无线网卡

    新买了一台Lenovo Y430P的笔记本,笔记本自带的无线网卡型号是BCM43142.安装了CentOS6.5的操作系统后,按照网上搜索到的网址http://zh-cn.broadcom.com/s ...

  6. Oracle按不同时间分组统计

    Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...

  7. 值为NULL的对象指针

    相信大家对NULL不会很陌生,NULL 是一个标准规定的宏定义,用来表示空指针常量,当一个指针变量被赋值为NULL时,表示它不再指向任何有效地址,无法在访问任何数据.在VS2012库文件stdio.h ...

  8. PowerDesigner如何把建好的表导入到数据库中,并且把注释也导入进去

    第一次接触这个软件,经过自己的捣鼓和百度,终于可以顺利的导入数据库中了,好开森,希望可以帮助到更多人. 数据库(mysql)其实和sqlserver差不多,以16.5版本为例 1.选中一个PDM项目, ...

  9. java 各数据类型之间的转换

    String —> Date SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date ...

  10. poj3162(树形dp&plus;优先队列)

    Walking Race Time Limit: 10000MS   Memory Limit: 131072K Total Submissions: 5409   Accepted: 1371 Ca ...