Codeforces Round #492 (Div. 2) [Thanks, uDebug!]
这次的题好奇怪哦。。。
思路:先把跟停车位相邻的车停进去,然后开始转圈。。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = ;
const int M = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int a[][N], n, k;
vector<int> ans[]; pii getPos(int id) {
if (id < n) return mk(, id);
else return mk(, * n - - id);
} void add(int x, int y, int z) {
ans[].push_back(x);
ans[].push_back(y);
ans[].push_back(z);
} int main() {
scanf("%d%d", &n, &k); for(int i = ; i < ; i++) {
for(int j = ; j < n; j++) {
scanf("%d", &a[i][j]);
}
} for(int j = ; j < n; j++) {
if(a[][j] == ) continue;
if(a[][j] == a[][j]) {
add(a[][j], , j);
k--;
a[][j] = ;
}
} for(int j = ; j < n; j++) {
if(a[][j] == ) continue;
if(a[][j] == a[][j]) {
add(a[][j], , j);
k--;
a[][j] = ;
}
} if(k == * n) {
puts("-1");
return ;
} while(k > ) {
for(int i = ; i < * n; i++) {
pii u = getPos(i);
if(a[u.first][u.second] == ) continue;
if(a[u.first ^ ][u.second] == a[u.first][u.second]) {
add(a[u.first][u.second], u.first ^ , u.second);
k--;
a[u.first][u.second] = ;
continue;
} pii v = getPos((i + * n - ) % ( * n));
if(a[v.first][v.second] != ) continue;
add(a[u.first][u.second], v.first, v.second);
swap(a[u.first][u.second], a[v.first][v.second]);
}
} printf("%d\n", ans[].size());
for(int i = ; i < ans[].size(); i++) {
printf("%d %d %d\n", ans[][i], ans[][i] + , ans[][i] + );
} return ;
}
E:
题目大意:给你n个长度小于1e6的向量,让你把每个向量变成正向或者负向,使得所有向量加起来的长度不超过1.5 * 1e6
思路:正解是每三个向量中都能找到两个向量合起来 <= 1e6,然后不断合并,最后只会剩下一个或者两个向量,
如果一个向量肯定 <= 1e6, 如果是两个向量一定 <= 1.5 * 1e6。。。
但是可以用随机洗牌的方法去贪心,因为能卡掉的数据特别不好造。。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int M = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, ans[N], id[N];
LL base = 1500000ll * ;
struct Vector {
Vector(LL x = , LL y = ) {
this->x = x;
this->y = y;
} Vector operator + (const Vector &rhs) const {
return Vector(x + rhs.x, y + rhs.y);
} Vector operator - (const Vector &rhs) const {
return Vector(x - rhs.x, y - rhs.y);
} LL len() {
return x * x + y * y;
} LL x, y, id;
}a[N]; int main(){
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%lld%lld", &a[i].x, &a[i].y);
id[i] = i;
} while() {
random_shuffle(id + , id + n);
Vector now;
for(int i = n; i >= ; i--) {
int pos = id[i];
Vector nx1 = now + a[pos];
Vector nx2 = now - a[pos];
if(nx1.len() <= nx2.len()) {
now = nx1;
ans[pos] = ;
} else {
now = nx2;
ans[pos] = -;
}
} if(now.len() <= base) {
for(int i = ; i <= n; i++) {
printf("%d ", ans[i]);
}
puts("");
return ;
}
}
return ;
} /*
*/
Codeforces Round #492 (Div. 2) [Thanks, uDebug!]的更多相关文章
- [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]
http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...
- Codeforces Round #492 (Div. 2)
A. /* 从大往小依次除 */ #include<cstdio> #include<algorithm> #include<cstring> #include&l ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- jquery读取html5的data-属性
前端代码的工作无非就是接收后端发来的数据,展示到前端页面:又或者,给无数的按钮,图片,段落等绑定各种事件.那么我们在绑定事件是需要拿取HTML页面的元素,以及在拿取的元素给定各式各样的自定义属性.当需 ...
- javaFX8初探(环境搭建)
1:下载java8 Oracle官网2:下载eclipse4.4 eclipse官网3:安装e(fx)clipse插件 http://download.eclipse.org/efxclipse/u ...
- openstack配置模块
一.简介 openstack中负责处理配置的模块是oslo.config,它可以处理配置项和配置文件.通常的配置处理都是如下形式: from oslo.config import cfg CONF=c ...
- spfa+剪枝 或者 dij+手写堆+剪枝 UOJ 111
http://uoj.ac/problem/111 好像NOIP里面的题目...有好多都是...能通过xjbg剪枝来...AC题目的? 得好好学一下这些剪枝黑科技了... 思路:我觉得这位大佬说的很完 ...
- [php]unset函数
unset($var); 释放一个变量空间 unset($var1, $var2...);释放多个变量空间 unset(var['数组元素内容']);释放数组元素 注意: 1.在函数内部释放全局变量和 ...
- Count on a tree(SPOJ COT + 树上第k大 + 主席树 + LCA)
题目链接:https://www.spoj.com/problems/COT/en/ 题目: 题意: 给你一棵有n个节点的树,求节点u到节点v这条链上的第k大. 思路: 我们首先用dfs进行建题目给的 ...
- CAD启动提示"是否关闭命令行"不管点击什么,都会闪退的解决办法
AutoCAD splash screen starts up and then closes AutoCAD splash screen starts up and then closes (S ...
- D - Keiichi Tsuchiya the Drift King Gym - 102028D (几何)
题目链接:https://cn.vjudge.net/contest/275150#problem/D 题目大意: 问你能满足那个矩形可以顺利通过的条件,然后求出最小的w 具体思路:首先,我们应该将情 ...
- Hbuilder连接第3方模拟器(夜神)
http://www.bcty365.com/content-146-5148-1.html
- html5优分期大学生分期购物商城模板
链接:http://pan.baidu.com/s/1dEUAzBz 密码:j150