首页 > 代码库 > 【HDOJ】1107 武林
【HDOJ】1107 武林
简单模拟,题目数据太弱太弱了。
1 /* 1107 */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <cstdlib> 6 #include <vector> 7 #include <algorithm> 8 using namespace std; 9 10 typedef struct node_t { 11 int x, y; // position 12 int nl; // 内力 13 int wy; // 武艺 14 int hp; // 生命 15 bool hasFight; 16 int d; // direction: 0:up, down:1 17 node_t() {} 18 node_t(int xx, int yy, int nnl, int wwy, int hhp, bool h=false, int dd=0) { 19 x = xx; y = yy; nl = nnl; wy = wwy; 20 hp = hhp; hasFight=h; d = dd; 21 } 22 } node_t; 23 24 int map[15][15]; 25 vector<node_t> vnodes[3]; // 0:少林, 1:武当, 2:峨眉 26 int dir[3][2][2] = { 27 { {1, 0}, {-1, 0} }, 28 { {0, 1}, {-1, 0} }, 29 { {1, 1}, {-1, -1} } 30 }; 31 int nn[3]; 32 int t, n; 33 34 void init() { 35 memset(map, 0, sizeof(map)); 36 for (int i=0; i<3; ++i) { 37 vnodes[i].clear(); 38 nn[i] = 0; 39 } 40 } 41 42 inline bool check(int x, int y) { 43 return x>0 && x<13 && y>0 && y<13; 44 } 45 46 int getDPS(int i, int j) { 47 double tmp; 48 49 if (i == 0) { 50 tmp = (0.5*vnodes[i][j].nl + 0.5*vnodes[i][j].wy) * (vnodes[i][j].hp + 10.) / 100.0; 51 } else if (i == 1) { 52 tmp = (0.8*vnodes[i][j].nl + 0.2*vnodes[i][j].wy) * (vnodes[i][j].hp + 10.) / 100.0; 53 } else { 54 tmp = (0.2*vnodes[i][j].nl + 0.8*vnodes[i][j].wy) * (vnodes[i][j].hp + 10.) / 100.0; 55 } 56 57 return (int) tmp; 58 } 59 60 void fight() { 61 int dps0, dps1; 62 int i, j, k, p; 63 int ii, jj, kk; 64 int x, y; 65 66 for (i=0; i<3; ++i) { 67 for (j=0; j<nn[i]; ++j) { 68 if (vnodes[i][j].hp>0 && map[vnodes[i][j].x][vnodes[i][j].y]==2 && !vnodes[i][j].hasFight) { 69 x = vnodes[i][j].x; 70 y = vnodes[i][j].y; 71 vnodes[i][j].hasFight = true; 72 for (ii=0; ii<3; ++ii) { 73 if (ii == i) 74 continue; 75 for (jj=0; jj<nn[ii]; ++jj) { 76 if (vnodes[ii][jj].hp>0 && vnodes[ii][jj].x==x && vnodes[ii][jj].y==y) { 77 dps0 = getDPS(i, j); 78 dps1 = getDPS(ii, jj); 79 vnodes[i][j].hp -= dps1; 80 vnodes[ii][jj].hp -= dps0; 81 vnodes[ii][jj].hasFight = true; 82 } 83 } 84 } 85 } 86 } 87 } 88 } 89 90 void move() { 91 int i, j, k; 92 int x, y, xx, yy; 93 94 for (i=0; i<3; ++i) { 95 for (j=0; j<nn[i]; ++j) { 96 vnodes[i][j].hasFight = false; 97 x = vnodes[i][j].x; 98 y = vnodes[i][j].y; 99 --map[x][y];100 k = vnodes[i][j].d;101 if (i == 0) {102 if (x == 12) k = 1;103 if (x == 1) k = 0;104 if (k) {105 --x;106 } else {107 ++x;108 }109 } else if (i == 1) {110 if (y == 12) k = 1;111 if (y == 1) k = 0;112 if (k) {113 --y;114 } else {115 ++y;116 }117 } else {118 if (x==12 || y==12)119 k = 1;120 if (x==1 || y==1)121 k = 0;122 if ((x==1&&y==12) || (x==12 && y==1))123 /* do nothing */;124 else {125 if (k) {126 --x; --y;127 } else {128 ++x; ++y;129 }130 }131 }132 vnodes[i][j].d = k;133 vnodes[i][j].x = x;134 vnodes[i][j].y = y;135 ++map[x][y];136 }137 }138 }139 140 int main() {141 int i, j, k, tmp;142 int x, y, nl, wy, hp;143 char cmd[3];144 145 #ifndef ONLINE_JUDGE146 freopen("data.in", "r", stdin);147 freopen("data.out", "w", stdout);148 #endif149 150 scanf("%d", &t);151 while (t--) {152 init();153 scanf("%d", &n);154 while (scanf("%s", cmd)!=EOF && (cmd[0]!=‘0‘)) {155 scanf("%d %d %d %d %d", &x, &y, &nl, &wy, &hp);156 if (cmd[0] == ‘S‘) j = 0;157 if (cmd[0] == ‘W‘) j = 1;158 if (cmd[0] == ‘E‘) j = 2;159 ++map[x][y];160 vnodes[j].push_back(node_t(x,y,nl,wy,hp));161 ++nn[j];162 }163 while (n--) {164 fight();165 move();166 }167 for (i=0; i<3; ++i) {168 k = 0;169 n = 0;170 for (j=0; j<nn[i]; ++j) {171 if (vnodes[i][j].hp > 0) {172 k += vnodes[i][j].hp;173 ++n;174 }175 }176 printf("%d %d\n", n, k);177 }178 puts("***");179 }180 181 return 0;182 }
【HDOJ】1107 武林
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。