前三题水

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5; int main() {
int n, a, b; std::cin >> n >> a >> b;
int bb = b;
if (b < 0) bb = -b;
while (bb--) {
if (b < 0) {
a--;
} else {
a++;
}
if (a == 0) {
a = n;
} else if (a == n + 1) {
a = 1;
}
}
std::cout << a << '\n'; return 0;
}

#include <bits/stdc++.h>

typedef long long ll;
const int M = 1e4 + 5;
struct Info {
std::string name;
int score;
bool operator < (const Info &rhs) const {
return score > rhs.score;
}
};
std::vector<Info> vec[M]; bool same_three(int a, int b, int c) {
return b == c;
} bool same(int id) {
return same_three (vec[id][0].score, vec[id][1].score, vec[id][2].score);
} int main() {
int n, m; std::cin >> n >> m;
std::string str; int num, score;
for (int i=0; i<n; ++i) {
std::cin >> str >> num >> score;
vec[num].push_back ((Info) {str, score});
}
for (int i=1; i<=m; ++i) {
if (vec[i].size () < 2) {
puts ("?");
continue;
} else {
std::sort (vec[i].begin (), vec[i].end ());
if (vec[i].size () > 2 && same (i)) {
puts ("?");
} else {
std::cout << vec[i][0].name << " " << vec[i][1].name << '\n';
}
}
} return 0;
}

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5;
std::map<int, bool> vis; int main() {
int n, m; scanf ("%d%d", &n, &m);
for (int a, i=0; i<n; ++i) {
scanf ("%d", &a);
vis[a] = true;
}
std::vector<int> vec;
int now = 1;
while (m - now >= 0) {
if (vis[now]) {
now++;
} else {
m -= now;
vec.push_back (now);
now++;
}
}
printf ("%d\n", vec.size ());
for (int i=0; i<vec.size (); ++i) {
printf ("%d%c", vec[i], i == vec.size () - 1 ? '\n' : ' ');
} return 0;
}

几何(叉积) D - Bicycle Race

题意:一个人从最下面的位置逆时针沿着湖转一圈,当转角指向湖的方向认为是危险的,问有多少个危险的转角.

分析:分类讨论也就四种情况,但是注意出发点不一定是最左边的(最下面的);也可以用叉积来判断,大于0表示是顺时针满足危险的定义.

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e4 + 5;
struct Point {
int x, y;
};
Point point[N]; int main() {
int n; scanf ("%d", &n);
for (int i=0; i<=n; ++i) {
scanf ("%d%d", &point[i].x, &point[i].y);
}
int ans = 0;
for (int i=0; i<n-2; ++i) {
if (point[i].x == point[i+1].x) {
if (point[i+1].y > point[i].y) {
if (point[i+2].x < point[i+1].x) {
ans++;
}
} else {
if (point[i+2].x > point[i+1].x) {
ans++;
}
}
} else {
if (point[i].x < point[i+1].x) {
if (point[i+1].y < point[i+2].y) {
ans++;
}
} else {
if (point[i+1].y > point[i+2].y) {
ans++;
}
}
}
}
printf ("%d\n", ans); return 0;
}
#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e4 + 5;
struct Point {
int x, y;
Point operator - (const Point &rhs) const {
return (Point) {x - rhs.x, y - rhs.y};
}
};
Point point[N];
typedef Point Vector; int cross(Vector A, Vector B) {
return A.x * B.y - A.y * B.x;
} int main() {
int n; scanf ("%d", &n);
for (int i=0; i<=n; ++i) {
scanf ("%d%d", &point[i].x, &point[i].y);
}
int ans = 0;
for (int i=1; i<n; ++i) {
if (cross (point[i-1] - point[i], point[i+1] - point[i]) < 0) {
ans++;
}
}
printf ("%d\n", ans); return 0;
}

图论 E - New Reform

题意:n个点,m条边,每条边是单向的,问如何安排每条边的方向使得入度为0的点最少,最少是几个.

分析:进行DFS,如果访问到已访问过的点表示该连通块有环,也就是可以满足每个点的入度大于等于1.

#include <bits/stdc++.h>

const int N = 1e5 + 5;

std::vector<int> G[N];
bool vis[N];
int n, m, add; void DFS(int u, int fa) {
if (vis[u]) {
add = 0;
return ;
}
vis[u] = true;
for (int i=0; i<G[u].size (); ++i) {
int v = G[u][i];
if (v == fa) {
continue;
}
DFS (v, u);
}
} int main() {
scanf ("%d%d", &n, &m);
for (int i=0; i<m; ++i) {
int u, v; scanf ("%d%d", &u, &v);
G[u].push_back (v);
G[v].push_back (u);
}
int ans = 0;
for (int i=1; i<=n; ++i) {
if (vis[i]) {
continue;
}
add = 1;
DFS (i, 0);
ans += add;
}
printf ("%d\n", ans); return 0;
}

并查集 F - Polycarp and Hay

题意:n*m的矩阵有不同高度的干草,现要割成高度相同的连通块,且其中至少一个干草的高度没有变化,以及连通块的高度和等于k,求可行的方案.

分析:统计出每个可以高度不变化且被k整除,且连通块数量不小于k/a[i][j],那么BFS一次能的得到方案.按照高度从大到小排序,对于当前的干草累加上周围高度不小于它的连通块数量,DP思想或者说是求前缀,用并查集维护.

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e3 + 5;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
ll a[N][N];
bool vis[N][N];
int n, m;
ll k, num, aim; int rt[N*N], rk[N*N];
int Find(int x) {
return rt[x] == -1 ? x : rt[x] = Find (rt[x]);
}
void Union(int x, int y) {
x = Find (x);
y = Find (y);
if (x == y) {
return ;
}
rt[x] = y;
rk[y] += rk[x];
} struct Info {
ll val;
int x, y;
bool operator < (const Info &rhs) const {
return val > rhs.val;
}
};
std::vector<Info> vec; bool judge(int x, int y) {
if (x < 1 || x > n || y < 1 || y > m) {
return false;;
}
return true;
} void BFS(int x, int y) {
std::queue<std::pair<int, int> > que;
que.push (std::make_pair (x, y));
vis[x][y] = true; num--; while (!que.empty ()) {
int nx = que.front ().first, ny = que.front ().second;
que.pop ();
for (int i=0; i<4; ++i) {
int tx = nx + dx[i];
int ty = ny + dy[i];
if (num == 0) {
continue;
}
if (!judge (tx, ty)) {
continue;
}
if (vis[tx][ty]) {
continue;
}
if (a[tx][ty] < aim) {
continue;
}
vis[tx][ty] = true; num--;
que.push (std::make_pair (tx, ty));
}
}
} void print() {
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
if (vis[i][j]) {
printf ("%I64d ", aim);
} else {
printf ("0 ");
}
}
puts ("");
}
} int main() {
scanf ("%d%d%I64d", &n, &m, &k);
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
scanf ("%I64d", &a[i][j]);
vec.push_back ((Info) {a[i][j], i, j});
}
}
std::sort (vec.begin (), vec.end ());
memset (rt, -1, sizeof (rt));
std::fill (rk, rk+N*N, 1); for (int i=0; i<vec.size (); ++i) {
Info &r = vec[i];
if (r.val == 0) {
break;
}
for (int j=0; j<4; ++j) {
int tx = r.x + dx[j];
int ty = r.y + dy[j];
if (!judge (tx, ty)) {
continue;
}
if (a[tx][ty] >= r.val) {
Union ((tx-1)*m+ty, (r.x-1)*m+r.y);
}
}
int fa = Find ((r.x-1)*m+r.y);
if (k % r.val != 0 || k / r.val > rk[fa]) {
continue;
}
puts ("YES");
num = k / r.val; aim = r.val;
BFS (r.x, r.y);
print ();
return 0;
}
puts ("NO"); return 0;
}

  

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

  1. Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)

    Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...

  2. Codeforces Round #346 (Div. 2) A Round-House

    A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...

  3. Codeforces Round #346 (Div. 2) A. Round House 水题

    A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...

  4. Codeforces Round #346 (Div. 2) D Bicycle Race

    D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...

  5. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  6. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  7. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

  8. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs

    F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...

  9. Codeforces Round #346 (Div. 2) E. New Reform dfs

    E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities ...

  10. Codeforces Round #346 (Div. 2) D. Bicycle Race 叉积

    D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates ...

随机推荐

  1. IOS- 自定义 UIButton

    #pragma mark init方法内部默认会调用initWithFrame: - (id)initWithFrame:(CGRect)frame { self = [super initWithF ...

  2. 零基础十分钟学会用git在coding.net上传(pull)和push

    ---恢复内容开始--- 对于入门者来说,特别是刚刚接触计算机的人来说,模仿是最快的学习方式了,先能够会使用(对于初学者来说,这种使用新事物的感觉很能爽的)至于原理,以后再说.下面先让初学者快速的学会 ...

  3. String[] a = new String[]{"1","2"},我如果想增加一个"3"到a中,如何增加?

    在java中数组是定长的,当你声明了数组的大小后数组的长度就不能改变在你的程序中,数组的初始化大小为2,a[0]="1";a[1]="2",所以无法产生元素a[ ...

  4. 【SSO单点系列】(1):CAS4.0 环境的搭建

    一.概述 今天开始写CAS相关的第一篇文章,这篇文章主要是关于CAS环境的搭配,提供给刚刚接触CAS的一个入门指南,并演示一个CAS的最简单的实例 二.环境要求 博主的环境如下: win8.1 64 ...

  5. NYOJ题目62笨小熊

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAK1CAIAAAChInrhAAAgAElEQVR4nO3dO3LjutaG4X8Szj0Qxx

  6. 按键使用方法(二)------verilog

    这里我们要验证一键两用的情况:点击与长击,单击与双击 代码: /********************************Copyright*************************** ...

  7. NMON中的各项参数指标

    一.NMON中的各项参数指标: SYS_SUMM:显示当前服务器的总体性能情况 Total System I/OStatistics:Avg tps during an interval:显示采集间隔 ...

  8. JAVA一些常用的时间操作

    项目中经常有对时间进行处理的需求,下面是一些常用的操作整理,方便以后再次使用以及做相关复习. 1.字符串转换为日期 /** * 字符串转换为日期 * @param dateStr 需要转换的日期 * ...

  9. securecrt 用心跳保持连接

    选项->会话->终端->发送协议NO-OP(P)

  10. settimeout,cleartimeout的使用分析

    设置时间的定时轮回执行,大家想到的js也就是settimeout这个方法,这个方法确实能够实现定时反复执行的功能,clearttimeout这是清理或者是暂停轮回执行的情况.可是发现clearttim ...