HDU 3031 ToBe Or Not To Be(模拟)
2016-03-09 23:31
555 查看
题意:
给你一堆牌,再给你5种操作牌,两个人轮流抓操作牌,并且按照操作来执行,最后谁手里的牌多谁就赢。
明明是左偏树的题目,但是我用priority_queue水过去了。。。
代码:
给你一堆牌,再给你5种操作牌,两个人轮流抓操作牌,并且按照操作来执行,最后谁手里的牌多谁就赢。
明明是左偏树的题目,但是我用priority_queue水过去了。。。
代码:
[code]#include <queue> #include <math.h> #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #define N 200 + 5 using namespace std; typedef struct { int num ,v; double x ,y ,z; }NODE; typedef struct { double dis; int v ,id; }ZT; NODE node1 ,node2 ; ZT zt ; int map ,G_b ; int nowb ,nowg ; int mark ; bool camp(ZT a ,ZT b) { return a.dis < b.dis || a.dis == b.dis && a.v > b.v; } void Marr(int n) { queue<int>q; for(int i = 1 ;i <= n ;i ++) q.push(i); memset(mark ,0 ,sizeof(mark)); memset(nowb ,255 ,sizeof(nowb)); memset(nowg ,255 ,sizeof(nowg)); while(!q.empty()) { int xin ,tou = q.front(); q.pop(); for(int i = 1 ;i <= n ;i ++) { xin = map[tou][i]; if(mark[tou][xin]) continue; mark[tou][xin] = 1; if(nowg[xin] == -1) { nowg[xin] = tou; nowb[tou] = xin; break; } else { if(G_b[xin][tou] > G_b[xin][nowg[xin]]) { q.push(nowg[xin]); nowg[xin] = tou; nowb[tou] = xin; break; } } } } return; } double get_dis(NODE a ,NODE b) { double xx = (a.x - b.x) * (a.x - b.x); double yy = (a.y - b.y) * (a.y - b.y); double zz = (a.z - b.z) * (a.z - b.z); return xx + yy + zz; } int main () { #ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout); #endif int t ,n ,i ,j; scanf("%d" ,&t); while(t--) { scanf("%d" ,&n); for(i = 1 ;i <= n ;i ++) scanf("%d %d %lf %lf %lf" ,&node1[i].num ,&node1[i].v ,&node1[i].x ,&node1[i].y ,&node1[i].z); for(i = 1 ;i <= n ;i ++) scanf("%d %d %lf %lf %lf" ,&node2[i].num ,&node2[i].v ,&node2[i].x ,&node2[i].y ,&node2[i].z); for(i = 1 ;i <= n ;i ++) { for(j = 1 ;j <= n ;j ++) { zt[j].dis = get_dis(node1[i] ,node2[j]); zt[j].v = node2[j].v; zt[j].id = j; // cout << zt[j].dis << endl; } sort(zt + 1 ,zt + n + 1 ,camp); for(j = 1 ;j <= n ;j ++) map[i][j] = zt[j].id; } // for (int i=1;i <= n; i++) { // for (int j = 1; j <= n; j++) cout << map[i][j] << ' '; // cout << endl; // } for(i = 1 ;i <= n ;i ++) { for(j = 1 ;j <= n ;j ++) { zt[j].dis = get_dis(node2[i] ,node1[j]); // cout << node1[j].num << ' ' << node1[j].v << ' ' << node1[j].x << ' ' << node1[j].y << ' ' << node1[j].z << endl; // cout << zt[j].dis << endl; zt[j].v = node1[j].v; zt[j].id = j; } sort(zt + 1 ,zt + n + 1 ,camp); for(j = 1 ;j <= n ;j ++) G_b[i][zt[j].id] = n - j + 1; } // for (int i = 1; i <= n; i++) { // for (int j = 1; j <= n; j++) cout << G_b[i][j] << ' ' ; // cout << endl; // } Marr(n); for(i = 1 ;i <= n ;i ++) printf("%d %d\n" ,node1[i].num ,node2[nowb[i]].num); puts(""); } return 0; }
相关文章推荐
- Ubuntu下搭建Web服务器(Apache+PHP+MySQL)及初始配置
- 数据结构学习->经验总结1
- Python3.x和Python2.x的区别
- Kaggle(1):数据挖掘的基本流程
- Linux初学者的感受
- 半数集问题
- MVC 过滤器的执行顺序 AOP面向切面编程
- 最短路思路
- 编程小练习3
- 【Data Algorithms_Recipes for Scaling up with Hadoop and Spark】Chapter3 Top 10 NonUniqueList
- 验证
- 微信支付
- git使用的学习
- 关于VO、PO的理解——java的(PO,VO,TO,BO,DAO,POJO)解释
- 实验(一)
- 让Bean获取Spring容器
- STL set
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
- 学习进度总结
- 安装小tips (关于pycharm5.0 ,git2.7)