Colorado Potato Beetle(CF的某道) & 鬼畜宽搜
题意:
一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题...
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的某道) & 鬼畜宽搜的更多相关文章
- Codeforces243C-Colorado Potato Beetle(离散化+bfs)
Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. Th ...
- Codeforces Round #150 (Div. 2)
A. Dividing Orange 模拟. B. Undoubtedly Lucky Numbers 暴力枚举\(x.y\). C. The Brand New Function 固定左端点,右端点 ...
- 「Luogu P3183」[HAOI2016]食物链 解题报告
身为一个蒟蒻,由于刷不过[NOI2001]食物链 于是出门左转写了道另一道假的食物链 戳这里 这里的食物链个条数其实就是有向图的路径数(应该是这么说吧,我弱) 思路: 拓扑(Topulogy)(一本正 ...
- cf 834 E. Ever-Hungry Krakozyabra
cf 834 E. Ever-Hungry Krakozyabra(爆搜+数位dp) 题意: 定义一种inedible tail为一个数把每一位数字按不降的顺序排列后,去掉前导0组成的序列 比如570 ...
- 【HDOJ】3029 Scales
CF上有道类似的,做了那个这个简单多了.思路是取模.模等于1如何处理,模等于2如何分类分类讨论后.可解.解得对数据排序后再输出. /* 3029 */ #include <iostream> ...
- noip2017普及 兔纸游玩记
初中的最后一场比赛...就这样结束了吧...QAQ时间...真够快的qwq 应该是初中的最后一篇游记了吧,尽量写多点... 这是一篇,初三 老年菜兔的 noip2017 普及游玩记吧! DAY 0 ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
- CF911E Stack Sorting
洛谷题目链接:CF911E Stack Sorting Codeforces题目链接:Stack Sorting 题意翻译 给你一排列的一部分,让你补全整个排列使其字典序最大并且经过一个栈调整顺序之后 ...
- pat甲级题解(更新到1013)
1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...
随机推荐
- CLR via C#(13)-浅谈事件
提起事件,我们都不陌生,事件使类之间有了交互的能力.它是建立在委托基础上的.有了前面对委托的了解,相信读起事件来也不会太难了.关于事件,现成的好文章数不胜数,本不打算写了.不过问道有先后,各抒己见,也 ...
- jquery学习笔记-----ajax
$(selector).load( url [,date] [,callback] ) url:请求页面的url地址 date:发送至服务器的key:value数据 callback:请求完成时的回调 ...
- Java集合源码学习(一)集合框架概览
>>集合框架 Java集合框架包含了大部分Java开发中用到的数据结构,主要包括List列表.Set集合.Map映射.迭代器(Iterator.Enumeration).工具类(Array ...
- Validform 学习笔记---基础知识整理
面对表单的验证,自己写大量的js毕竟不是一个明智的做法.不仅仅是代码很长而且不便于梳理.Validform就是一款开源的第三方验证js的控件,通过添加相应的js以及css能够有效的验证表单,维护起来也 ...
- Android 大牛的 blog 值得推荐 (转 整理)
1 收集了 国外著名开发者 25 人,包括 Github 地址.Blog 地址以及重点贡献介绍 链接 收集了 国内部分开发者 32人,包括 Github 地址.Blog 地址以及重点贡献介绍, 链接 ...
- 关于如何在MFC工程中输入不同的数据进行调试
我们可以采用c++的文件输入输出来进行调试 这样就绕过了不能使用黑窗口输入数据就不能调试的思维定式 不是黑窗口的我们都可以考虑用文件流输入输出 或者用控件来输入? http://blog.csdn.n ...
- 删除表数据drop、truncate和delete的用法
说到删除表数据的关键字,大家记得最多的可能就是delete了 然而我们做数据库开发,读取数据库数据.对另外的两兄弟用得就比较少了 现在来介绍另外两个兄弟,都是删除表数据的,其实也是很容易理解的 老大- ...
- hdu1159 最长公共子序列
Common Subsequence Problem Description A subsequence of a given sequence is the given sequence with ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- DSP using MATLAB 示例 Example3.15
上代码: subplot(1,1,1); b = 1; a = [1, -0.8]; n = [0:100]; x = cos(0.05*pi*n); y = filter(b,a,x); figur ...