题意:

  一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题...

SOL:

  与其说这是一道图论题不如说是一道生动活泼的STL-vector教学....

  离散化宽搜,没什么别的...vector用得淋漓尽致...

Code:

  

/*==========================================================================
# Last modified: 2016-03-18 08:32
# Filename: t1.cpp
# Description:
==========================================================================*/
#define me AcrossTheSky
#include <cstdio>
#include <ctime>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <deque> #define lowbit(x) (x)&(-x)
#define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++)
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define getlc(a) ch[(a)][0]
#define getrc(a) ch[(a)][1]
#define pb push_back
#define find(a,b) lower_bound((a).begin(), (a).end(), (b))-(a).begin() #define INF 10000000000
#define maxn 3000
#define maxm 100000
#define pi 3.1415926535898
#define _e 2.718281828459
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline
void read(T& num) {
bool start=false,neg=false;
char c;
num=0;
while((c=getchar())!=EOF) {
if(c=='-') start=neg=true;
else if(c>='0' && c<='9') {
start=true;
num=num*10+c-'0';
} else if(start) break;
}
if(neg) num=-num;
}
/*==================split line==================*/
ll n, x[maxn], x1 = INF/2, y1 = INF/2, ans = 0;
char d[maxn];
vector<ll> x2,y2;
int a[maxn][maxn];
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; void check(){
FORP(i,0,x2.size()-1) printf("%lld ",x2[i]);
printf("\n");
FORP(i,0,y2.size()-1) printf("%lld ",y2[i]);
cout << endl;
}
void mark(int ld,int rd,int lu,int ru) {
if (ld>lu) swap(ld,lu); if (rd>ru) swap(rd,ru);
for (int i=ld;i<=lu;i++)
for (int j=rd;j<=ru;j++) a[i][j] = 1;
}
queue<int> qx,qy;
void bfs() {
qx.push(0); qy.push(0);
while (!qx.empty()){
int nx=qx.front(),ny=qy.front();
qx.pop(); qy.pop();
FORP(i,0,3) {
int xx=nx+dx[i],yy=ny+dy[i];
if (xx<0||xx>=x2.size()||yy<0||yy>=y2.size()||a[xx][yy])
continue;
else {
a[xx][yy]=2;
qx.push(xx); qy.push(yy);
}
}
}
//FORP(i,0,3) dfs(xx+dx[i],yy+dy[i]);
}
void init(){
read(n);
x2.pb(0); x2.pb(INF);
y2.pb(0); y2.pb(INF);
FORP(i,0,n-1){
x2.pb(x1); x2.pb(x1+1);
y2.pb(y1); y2.pb(y1+1);
cin >> d[i]; read(x[i]);
if (d[i]=='R')x1+=x[i];if (d[i]=='L')x1-=x[i];
if (d[i]=='U')y1+=x[i];if (d[i]=='D')y1-=x[i];
}
x2.pb(x1); x2.pb(x1+1);
y2.pb(y1); y2.pb(y1+1);
// check();
sort(x2.begin(), x2.end()); sort(y2.begin(), y2.end());
x2.erase(unique(x2.begin(),x2.end()),x2.end());
y2.erase(unique(y2.begin(),y2.end()),y2.end()); // check();
}
int main(){
//freopen("a.in","r",stdin);
init(); int xnow=find(x2,INF/2),ynow=find(y2,INF/2);
ll xx=INF/2, yy=INF/2;
FORP(i,0,n-1){
int x4=xnow,y4=ynow;
if (d[i]=='R') xx+=x[i];if (d[i]=='L') xx-=x[i];
if (d[i]=='U') yy+=x[i];if (d[i]=='D') yy-=x[i];
xnow=find(x2,xx); ynow=find(y2,yy);
mark(xnow, ynow, x4, y4);
}
bfs(); FORP(i,0,x2.size()-1)
FORP(j,0,y2.size()-1)
if (a[i][j]!=2) ans+=(x2[i+1]-x2[i])*(y2[j+1]-y2[j]);
printf("%lld\n",ans);
return 0;
}

Colorado Potato Beetle(CF的某道) & 鬼畜宽搜的更多相关文章

  1. Codeforces243C-Colorado Potato Beetle(离散化+bfs)

    Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. Th ...

  2. Codeforces Round #150 (Div. 2)

    A. Dividing Orange 模拟. B. Undoubtedly Lucky Numbers 暴力枚举\(x.y\). C. The Brand New Function 固定左端点,右端点 ...

  3. 「Luogu P3183」[HAOI2016]食物链 解题报告

    身为一个蒟蒻,由于刷不过[NOI2001]食物链 于是出门左转写了道另一道假的食物链 戳这里 这里的食物链个条数其实就是有向图的路径数(应该是这么说吧,我弱) 思路: 拓扑(Topulogy)(一本正 ...

  4. cf 834 E. Ever-Hungry Krakozyabra

    cf 834 E. Ever-Hungry Krakozyabra(爆搜+数位dp) 题意: 定义一种inedible tail为一个数把每一位数字按不降的顺序排列后,去掉前导0组成的序列 比如570 ...

  5. 【HDOJ】3029 Scales

    CF上有道类似的,做了那个这个简单多了.思路是取模.模等于1如何处理,模等于2如何分类分类讨论后.可解.解得对数据排序后再输出. /* 3029 */ #include <iostream> ...

  6. noip2017普及 兔纸游玩记

    初中的最后一场比赛...就这样结束了吧...QAQ时间...真够快的qwq 应该是初中的最后一篇游记了吧,尽量写多点... 这是一篇,初三 老年菜兔的 noip2017 普及游玩记吧! DAY 0  ...

  7. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  8. CF911E Stack Sorting

    洛谷题目链接:CF911E Stack Sorting Codeforces题目链接:Stack Sorting 题意翻译 给你一排列的一部分,让你补全整个排列使其字典序最大并且经过一个栈调整顺序之后 ...

  9. pat甲级题解(更新到1013)

    1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...

随机推荐

  1. Android Message Handling Mechanism

    转自:http://solarex.github.io/blog/2015/09/22/android-message-handling-mechanism/ Android is a message ...

  2. MVC授权认证

    处于安全性考虑,MVC可以完成授权认证,授权认证的方式如下: 1.配置Config文件,设置登录页面: <authentication mode="Forms"> &l ...

  3. Go的基本示例

    有空可以看看, 不知能不能超越JAVA的作法. hello.go package main import "fmt" func main() { s := "hello& ...

  4. react.js 多个组件集成示例

    这个看得有点懵, 可能要结合其它实例看. html <!DOCTYPE html> <html> <head> <script src="http: ...

  5. 无废话ExtJs 入门教程三[窗体:Window组件]

    无废话ExtJs 入门教程三[窗体:Window组件] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3 ...

  6. 【Agorithm】一次一密加密解密算法

    #include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #inclu ...

  7. 微软改名部再次大显神威——ASP.NET 5改名ASP.NET Core 1.0

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:在计算机科学领域只有两件难事:缓存不可用和命名.--Phil Karlton 今天,S ...

  8. Effective C++ 之 Item 1: 视C++为一个语言联邦

    Effective C++ Chapter 1. 让自己习惯C++(Accustoming Yourself to C++) Item 1. 视C++为一个语言联邦(View C++ as a fed ...

  9. linux下vim配置以及一些常用的快捷键

    一些常用的vim编辑器快捷键: h」.「j」.「k」.「l」,分别控制光标左.下.上.右移一格. 按「ctrl」+「b」:屏幕往“后”移动一页. 按「ctrl」+「f」:屏幕往“前”移动一页. 按「c ...

  10. [导入]Eclipse 导入/编译 Hadoop 源码

    http://www.cnblogs.com/errorx/p/3779578.html 1.准备工作 jdk: eclipse: Maven: libprotoc :https://develope ...