Aizu 2302 On or Off
来源:互联网 发布:滴胶手机壳 知乎 编辑:程序博客网 时间:2024/06/05 04:26
传送门
暴力模拟
因为每个房间之间只有一条路,所以不用什么决策或者dp
dfs出每个点经过的时间,然后比较,
第一次经过一定要开灯和最后一次经过一定要关灯。所以只要经过了就需要加上
// whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define eps 1e-9#define PI acos(-1.0)#define INF 0x3f3f3f3f#define LLINF 1LL<<50#define speed std::ios::sync_with_stdio(false);typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define CPY(x,y) memcpy(x,y,sizeof(x))#define clr(a,x,size) memset(a,x,sizeof(a[0])*(size))#define cpy(a,x,size) memcpy(a,x,sizeof(a[0])*(size))#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define ls (idx<<1)#define rs (idx<<1|1)#define lson ls,l,mid#define rson rs,mid+1,r#define root 1,1,ntemplate<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------int ma[55][55],r,c,m;vector<int> t[55][55];pii road[3333];int on[55][55],off[55][55],cost[55][55];const int dir[4][2]= {0,1,0,-1,1,0,-1,0};char str[55];bool vis[55][55];pii task[1111];inline bool in(int x,int y){ return x>=0 && x<r && y>=0 && y<c;}int dfs(int x,int y,int ex,int ey,int step){ if(x==ex && y==ey) { return step; } for(int i=0; i<4; i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(in(xx,yy) && ma[xx][yy] && !vis[xx][yy]) { road[step]=mp(xx,yy); vis[xx][yy]=1; int temp=dfs(xx,yy,ex,ey,step+1); if(temp!=-1) return temp; vis[xx][yy]=0; } } return -1;}int main(){//freopen("data.txt","r",stdin); while(scanf("%d %d %d",&r,&c,&m)!=EOF) { for(int i=0; i<r; i++) { scanf("%s",str); for(int j=0; j<c; j++) { t[i][j].clear(); if(str[j]=='#') ma[i][j]=0; else ma[i][j]=1; } } for(int i=0; i<r; i++) for(int j=0; j<c; j++) read(cost[i][j]); for(int i=0; i<r; i++) for(int j=0; j<c; j++) read(on[i][j]); for(int i=0; i<r; i++) for(int j=0; j<c; j++) read(off[i][j]); for(int i=0; i<m; i++) read(task[i].first),read(task[i].second); t[task[0].first][task[0].second].pb(0); int time=0; for(int i=1; i<m; i++) { CLR(vis,0); vis[task[i-1].first][task[i-1].second]=1; int step=dfs(task[i-1].first,task[i-1].second,task[i].first,task[i].second,0); for(int j=0; j<step; j++) t[road[j].first][road[j].second].push_back(time+j+1); time+=step; } int ans=0; for(int i=0; i<r; i++) for(int j=0; j<c; j++) for(int k=0; k<t[i][j].size(); k++) { if(k) { if((t[i][j][k]-t[i][j][k-1])*cost[i][j] < on[i][j]+off[i][j]) ans+=(t[i][j][k]-t[i][j][k-1])*cost[i][j]; else ans+=on[i][j]+off[i][j]; } else ans+=on[i][j]+off[i][j]; } write(ans),putchar('\n'); } return 0;}
0 0
- Aizu 2302 On or Off
- Light on or off
- Hyper-Threading On or Off for Oracle?
- sharepoint2010---Turn on or turn off self-service site creation
- 如何得到当前“大写”键的状态“Caps Lock” ,On or Off。
- Insert 10000 tuples with "SET AUTOCOMMIT OFF" or no ON ML
- 学院OJ:1684:Light on or off __线段树 区间更新
- To Turn Recent Items On or Off in Start Menu Properties
- KSFetch Annoyance on Mac OS X 10.8 ML with ‘Hands Off’ or ‘Little Snitch’ Firewall.
- 自动增长的ID,插入特定的数字 set identity_insert ON OR OFF
- turn on/off webcache
- SET NOCOUNT { ON | OFF }
- set verify on/off
- SET NOCOUNT ON | OFF
- echo on|off
- Turn on/off monitor
- SET XACT_ABORT { ON | OFF }
- Set NoCount ON/OFF
- 遍历二叉树
- Ubuntu:useradd和adduser的区别
- Cocos2d-X 程序是如何开始运行与结束的
- U-boot-2014.04移植到MINI2440(4) 第一启动阶段start.S等详细分析
- 你应该掌握的七种回归技术
- Aizu 2302 On or Off
- 文件系统
- 通 用 接 口 说 明
- Cocos2dx Touch Move 距离计算
- 小吃
- hdu5002
- 使用cxf3.0.4搭建webservice服务需要的最精简jar包
- 猫猫学iOS 之CoreLocation反地理编码小Demo输入经纬度得到城市
- matlab 数据拟后绘图