题意:

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

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. 6个原因说服你选择PostgreSQL9.6

    PostgreSQL9.6在前些日子发布了, 社区为该版本的重大更新付诸良多, 发布日志一如既往的长,我挑选了6个重要的更新, 这些或许能够帮助你更好的使用PostgreSQL. 并行: 并行应该是这 ...

  2. 第一个JAVA创建

    1.file-new-java project  创建项目文件夹 2.在项目文件夹new-class 3.java对大小写比较敏感 输入代码 public class HELLOWORD { publ ...

  3. Cocoapods 更新后 使用

    platform:ios,'8.0'target 'APPNAME' do pod 'SMSSDK' pod 'MBProgressHUD', '0.9.1' pod 'AFNetworking', ...

  4. Linux下多窗口分屏式终端--Terminator

    很不错的分屏插件终端:https://pkgs.org/centos-6/repoforge-i386/terminator-0.95-3.el6.rf.noarch.rpm.html

  5. Java 解析XML的几种方法

    XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便. XML在不同的语言里解析方式都是一样的,只不过实现的语法不同而已. 基本的解析方式 ...

  6. SQL链表查询 数据库为空

    查询出数据为空,解决方案:链表 对应字段长度不一致.

  7. Solr入门之(6)配置文件solrconfig.xml

    solrconfig.xml包含了用于配置自身行为的绝大部分参数,其作用范围是当前core.该文件位于${solr_home}/solr/core1/conf/下. 参数列表概览: A.lib B.d ...

  8. play-framework的安装与使用

    一.下载: 到http://www.playframework.com/download下载 解压好包,然后输入: activator ui 访问:http://127.0.0.1:8888/home

  9. WIN7系统下U盘安装Ubuntu双系统

    1. 准备工作 1. 官网下载Ubantu镜像,我下载的是Ubantu14.04.3 LTS版本: 2. 下载 Universal USB Installer (UUI)用于制作U盘启动盘: 3. 下 ...

  10. ASP.NET MVC 4 WebAPI Simple Sample

    // Controllers.cs namespace Microshaoft.WebApi.Controllers { using Microshaoft.WebApi.Models; using ...