这次的题好奇怪哦。。。

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 ;
} /*
*/

最新文章

  1. 短期连载 第1回 万代南梦宫工作室动画的流派 BNS动作捕捉汐留工作室的采访
  2. 4201 TortoiseSVN常用配置
  3. angularJS中-$route路由-$http(ajax)的使用
  4. HDOJ 1062 Text Reverse
  5. Python [Leetcode 350]Intersection of Two Arrays II
  6. 关于Eclipse插件开发(五)-----编辑器类方法的使用说明
  7. Hibernate绑定参数
  8. JMM内存管理
  9. VSTO在幻灯片里面添加按钮对象
  10. 增强遍历和Object多参数遍历
  11. struts2使用模型传值
  12. Java框架数据库连接池比较 [转贴 2010-3-20 9:57:51]
  13. MFC中ComboBox控件用法
  14. idea integrate project
  15. ARP协议总结
  16. AR模型与数据平稳性之间的关系
  17. IBAction:IBOutlet:注意事项
  18. JWT+ASP.NET MVC 时间戳防止重放攻击
  19. 记开发个人图书收藏清单小程序开发(三)DB设计
  20. Java中LinkedList的fori和foreach效率比较

热门文章

  1. STL源码分析-iterator
  2. Java设计模式の命令模式
  3. spring boot 2.0.3+spring cloud (Finchley)7、服务链路追踪Spring Cloud Sleuth
  4. C11构造函数的改善
  5. 使用条件注释判断 IE 浏览器版本
  6. 【CodeForces】827 D. Best Edge Weight 最小生成树+倍增LCA+并查集
  7. DataFrame衍生新特征操作
  8. MySQL删除数据几种情况以及是否释放磁盘空间【转】
  9. git 还原到指定版本号
  10. Machine Learning系列--TF-IDF模型的概率解释