【codeforces 350C】Bombs
【链接】 我是链接,点我呀:)
【题意】
【题解】
会发现在x轴以及y轴上的炸弹,能用较少的操作数除掉。
而其他的点,会发现操作数都是一样的。
那么先把x,y轴上的点都除掉。
其他点。
我们优先沿着横坐标轴移动到和它相同位置。
然后再改变y坐标和目标炸弹一致。
然后就会发现。
x相同的话,要以y坐标的绝对值升序排,要优先处理y的绝对值小的点。
不然可能会出现走的过程中遇到另外一个炸弹的情况。
sort一波+贪心就好。
【代码】
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 1e5;
struct abc{
int x,y;
};
int n,cnt;
abc a[N+10];
bool cmp1(abc a,abc b){
return a.y<b.y;
}
bool cmp2(abc a,abc b){
return a.x<b.x;
}
bool cmp3(abc a,abc b){
if (a.x!=b.x)
return a.x<b.x;
else {
if (a.y<0 && b.y<0){
return a.y>b.y;
}else return a.y<b.y;
}
}
int main()
{
scanf("%d",&n);
rep1(i,1,n){
scanf("%d%d",&a[i].x,&a[i].y);
if (a[i].x==0 || a[i].y==0) cnt++;
}
printf("%d\n",cnt*4+(n-cnt)*6);
//从下到上排序.
sort(a+1,a+1+n,cmp1);
rep1(i,1,n)
if (a[i].x==0){
if (a[i].y>0){
printf("1 %d U\n",a[i].y);
puts("2");
printf("1 %d D\n",a[i].y);
puts("3");
}
}
rep2(i,n,1)
if (a[i].x==0){
if (a[i].y<0){
printf("1 %d D\n",-a[i].y);
puts("2");
printf("1 %d U\n",-a[i].y);
puts("3");
}
}
//从左往右排序
sort(a+1,a+1+n,cmp2);
rep1(i,1,n)
if (a[i].y==0){
if (a[i].x>0){
printf("1 %d R\n",a[i].x);
puts("2");
printf("1 %d L\n",a[i].x);
puts("3");
}
}
rep2(i,n,1)
if (a[i].y==0){
if (a[i].x<0){
printf("1 %d L\n",-a[i].x);
puts("2");
printf("1 %d R\n",-a[i].x);
puts("3");
}
}
sort(a+1,a+1+n,cmp3);
rep1(i,1,n)
if (a[i].x!=0 && a[i].y!=0){
printf("1 %d ",abs(a[i].x));if (a[i].x<0) puts("L");else puts("R");
printf("1 %d ",abs(a[i].y));if (a[i].y<0) puts("D");else puts("U");
puts("2");
printf("1 %d ",abs(a[i].y));if (a[i].y<0) puts("U");else puts("D");
printf("1 %d ",abs(a[i].x));if (a[i].x<0) puts("R");else puts("L");
puts("3");
}
return 0;
}
【codeforces 350C】Bombs的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- CF # 296 C Glass Carving (并查集 或者 multiset)
C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Extjs显示图片
1.首先做一个容器 xtype : 'container', // 第2行 anchor : '100%', layout : 'column', items : [{ columnWidth : 0 ...
- 【POJ 1011】 Sticks
[题目链接] http://poj.org/problem?id=1011 [算法] 深搜剪枝 首先我们枚举木棍的长度i,那么就有s/i根木棍,其中s为木棍长度的总和,朴素的做法就是对每种长度进行搜索 ...
- 树莓派(raspberry)启用root账户
树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的. debian里root账户默认没有密码,但账户锁定. 当需要root权限时,由默认账户经由sudo执行,Ras ...
- 棋盘问题(dfs)
http://poj.org/problem?id=1321 思路:按行搜索,回溯时还原棋盘. #include <stdio.h> #include <string.h> ] ...
- BN 详解和使用Tensorflow实现(参数理解)
Tensorflow BN具体实现(多种方式): 理论知识(参照大佬):https://blog.csdn.net/hjimce/article/details/50866313 补充知识: ① ...
- A - Fox And Snake
Problem description Fox Ciel starts to learn programming. The first task is drawing a fox! However, ...
- Spark Streaming基础概念
为了更好地理解Spark Streaming 子框架的处理机制,必须得要自己弄清楚这些最基本概念. 1.离散流(Discretized Stream,DStream):这是Spark Streamin ...
- 记录一个MySQL的问题
昨天做asp.net mvc程序,用mysql.data.entity.ef6做数据连接. 程序都是正常的,但就是提交数据的时候总是提示 Specified key was too long; max ...
- PL/SQL实现JAVA中的split()方法的小例子
众所周知,java中为String类提供了split()字符串分割的方法,所以很容易将字符串以指定的符号分割为一个字符串数组.但是在pl/sql中并没有提供像java中的split()方法,所以要想在 ...