hdu 4666Hyperspace
来源:互联网 发布:上饶市税务开票软件 编辑:程序博客网 时间:2024/05/19 01:13
曼哈顿距离,两个点设为(x1,y1),(x2,y2),其距离为|x1-x2|+|y1-y2|
#include <cstdio>#include <set>#include <cstring>#include <cstdlib>using namespace std;struct node{ int pos; int sum; bool operator < (const node &p) const { return p.sum>sum; } node (int x,int y) { pos=x; sum=y; }};set<node> s[34];int n,m,cnt;int f_a[34][5],v[5];bool d[60010];void dfs(int cur){ if(cur==m) { for(int i=0; i<m; ++i) f_a[cnt][i]=v[i]; s[cnt++].clear(); return; } v[cur]=1; dfs(cur+1); v[cur]=-1; dfs(cur+1);}void solve(int cur){ for(int i=0; i<cnt; ++i) { int a=0; for(int j=0; j<m; ++j) a+=v[j]*f_a[i][j]; s[i].insert(node(cur,a)); }}void del(){ int sum=0; for(int i=0; i<cnt; ++i) { set<node>::iterator p,q; while(s[i].size()) { p=s[i].begin(); if(d[p->pos]) s[i].erase(*p); else break; } while(s[i].size()) { q=s[i].end(); --q; if(d[q->pos]) s[i].erase(*q); else break; } if(!s[i].size()) continue; sum=max(sum,q->sum - p->sum); } printf("%d\n",sum);}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF) { int f,pos; cnt=0; memset(d,0,sizeof(bool)*(n+1)); dfs(0); for(int i=1; i<=n; ++i) { scanf("%d",&f); if(!f) for(int j=0; j<m; ++j) scanf("%d",&v[j]); else { scanf("%d",&pos); d[pos]=1; } if(!f) solve(i); del(); } } return 0;}
- HDU 4666 Hyperspace
- hdu-4666 Hyperspace
- hdu 4666 Hyperspace
- HDU 4666 Hyperspace
- hdu 4666 Hyperspace
- HDU 4666 Hyperspace
- hdu 4666Hyperspace
- HDU 4666 Hyperspace
- HDU 4666 Hyperspace
- HDU——4666 Hyperspace
- HDU 4666 Hyperspace 解题报告
- Hdu-4666 Hyperspace(曼哈顿距离)
- hdu 4666 Hyperspace 多校第七场
- hdu-4666-Hyperspace-最长曼哈顿距离
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- hdu 4666 Hyperspace (曼哈顿距离+set )
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- HDU 4666 Hyperspace(最长曼哈顿距离)
- errno的基本用法
- hdu 4669 Mutiples on a circle
- word中插入上下左右箭头
- 尚学堂马士兵Oracle学习笔记之一:基本select语句
- Computerworld 2014年8大热门IT技术预测
- hdu 4666Hyperspace
- MySQL用工具无法转存
- MongoDB无法启动(Error: couldn't connect to server 127.0.0.1:27017 src/mongo/ shell/mongo.js:91)
- Seasar之安装
- c/c++中static关键字的作用
- Java中的ReentrantLock和synchronized两种锁定机制的对比
- ubuntu下SVN服务器安装配置
- 2013-9-26-js计算日期天数差
- 在html标签中使用自定义属性及解决的实际问题