这次的题好奇怪哦。。。

C - Tesla

思路:先把跟停车位相邻的车停进去,然后开始转圈。。。

#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!]的更多相关文章

  1. [Codeforces Round #492 (Div. 1) ][B. Suit and Tie]

    http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...

  2. Codeforces Round #492 (Div. 2)

    A. /* 从大往小依次除 */ #include<cstdio> #include<algorithm> #include<cstring> #include&l ...

  3. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  4. 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 ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

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

  9. 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 ...

随机推荐

  1. Python2和Python3共存安装

    记录下: 先下载Python2.7.6,安装完成,不要添加到path中: 再下载Python3.4.3,安装,不要添加到path中. 进入 Python2: py -2 进入Python3: py - ...

  2. STL源码分析-内存分配器

    http://note.youdao.com/noteshare?id=744696e5f6daf0f2f03f10e381485e67

  3. cmd编译java程序出现:找不到或无法加载主类的原因以及解决办法 以及 给java的main方法传递args参数

    原因: 1.java源程序中没有主类main方法. 2.java源程序中包含有eclipse等IDE工具生成的package包. 解决办法(对应以上的原因): 1.运行含有main的类 2.将java ...

  4. 什么是JavaFX

    什么是JavaFX JavaFx平台是一个富客户端平台解决方案,它能够使用应用程序开发人员轻松的创建跨平台的富客户端应用程序.它构建在Java技术的基础之上,JavaFX平台提供了一组丰富的图形和媒体 ...

  5. 安装配置hexo icarus主题配置

    安装部分配置hexo icarus主题配置 安装icarus 直接下载主题模块放到blog项目 ,blog项目根目录执行 git clone https://github.com/ppoffice/h ...

  6. poj 1067 取石子游戏 (威佐夫博弈)

    取石子游戏 http://poj.org/problem?id=1067 Time Limit: 1000MS   Memory Limit: 10000K       Description 有两堆 ...

  7. Python学习笔记(四十一)— 内置模块(10)urllib

    摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432688314 ...

  8. css table-border

    1.table上设边框,td上设边框: <style> table{border-right:1px solid #F00;border-bottom:1px solid #F00} ta ...

  9. C语言实现线性表(链式存储方式)

    #include <stdio.h> #include <stdlib.h> //提供malloc()原型 typedef struct LNode *List; typede ...

  10. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...