栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1756 Robots

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1756 Robots

#include <stdio.h>  struct node {      int r;      int c;      int f;  };  int main()  {      struct node path[600], temp;      int r, c, step, i, j, n, total;      n = 0;      while(scanf("%d%d" , &r, &c)) {          if(r == -1 && c == -1) {   break;          }          else if(r == 0 && c == 0) {   for(i = 0; i < n-1; i++) {       for(j = 0; j < n-i-1; j++) {if(path[j].r > path[j+1].r ||     (path[j].r == path[j+1].r && path[j].c > path[j+1].c)) {        temp = path[j];        path[j] = path[j+1];        path[j+1] = temp;    }}       }       step = 0;       total = 0;       while(total < n) {i = 0;while(i < n && path[i].f) {    i++;}temp = path[i];path[i].f= 1;total += 1;step++;for(i = i+1; i < n; i++) {    if(!path[i].f) {        if(temp.r == path[i].r) { path[i].f = 1; temp = path[i]; total += 1;        }        else if(temp.r < path[i].r) { if(path[i].c >= temp.c) {     path[i].f = 1;     temp = path[i];     total += 1; }        }    }}       }       printf("%dn", step);       n = 0;   } else {       path[n].r = r;       path[n].f = 0;       path[n++].c = c;   }          }          return 0;  }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377571.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号