zoukankan      html  css  js  c++  java
  • 2012 金华现场赛K题

    http://acm.hdu.edu.cn/showproblem.php?pid=4452

    英语弱成渣,没看懂题目之前,样例没看明白。。trun around没注意。还有交换方向的时候理解错一句话,应该是题目写错了。

    模拟就是

    View Code
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 int main()
      5 {
      6     int n,t1,s1,t2,s2,k;
      7     char ch1,ch2;
      8     char temp1,temp2;
      9     int x1,y1,x2,y2;
     10     int i;
     11     int count1,count2;
     12     while(~scanf("%d",&n),n)
     13     {
     14           x1=y1=1;
     15           x2=y2=n;
     16           count1=0;
     17           count2=0;
     18           getchar();
     19           scanf("%c%d%d",&ch1,&s1,&t1);
     20           getchar();
     21           scanf("%c%d%d",&ch2,&s2,&t2);
     22           scanf("%d",&k);
     23           temp1=ch1;
     24           temp2=ch2;
     25           for(i=1;i<=k;i++)
     26           {
     27                 count1++;
     28                 count2++;
     29 
     30                 if(ch1=='E')
     31                 {
     32                       x1+=s1;
     33 
     34                       if(x1>n)
     35                       {
     36                             ch1='W';
     37                             x1=2*n-x1;
     38                       }
     39 
     40                 }
     41                 else if(ch1=='W')
     42                 {
     43 
     44                       x1-=s1;
     45                       if(x1<1)
     46                       {
     47                             ch1='E';
     48                             x1=2*1-x1;
     49                       }
     50                 }
     51 
     52                 else if(ch1=='N')
     53                 {
     54 
     55                       y1-=s1;
     56                       if(y1<1)
     57                       {
     58                             ch1='S';
     59                             y1=2*1-y1;
     60                       }
     61                 }
     62                 else if(ch1=='S')
     63                 {
     64                       y1+=s1;
     65 
     66                       if(y1>n)
     67                       {
     68 
     69                             ch1='N';
     70                             y1=2*n-y1;
     71                       }
     72                 }
     73 
     74                 if(ch2=='E')
     75                 {
     76                       x2+=s2;
     77 
     78                       if(x2>n)
     79                       {
     80                             ch2='W';
     81                             x2=2*n-x2;
     82                       }
     83 
     84                 }
     85                 else if(ch2=='W')
     86                 {
     87 
     88                       x2-=s2;
     89                       if(x2<1)
     90                       {
     91                             ch2='E';
     92                             x2=2*1-x2;
     93                       }
     94                 }
     95 
     96                 else if(ch2=='N')
     97                 {
     98 
     99                       y2-=s2;
    100                       if(y2<1)
    101                       {
    102                             ch2='S';
    103                             y2=2*1-y2;
    104                       }
    105                 }
    106                 else if(ch2=='S')
    107                 {
    108                       y2+=s2;
    109 
    110                       if(y2>n)
    111                       {
    112 
    113                             ch2='N';
    114                             y2=2*n-y2;
    115                       }
    116                 }
    117 
    118                //printf("%c   %c\n%d %d\n\n\n",ch2,ch1,y2,x2);
    119                 if(x1==x2&&y1==y2)
    120                 {
    121                       char tp;
    122                       tp=ch1;
    123                       ch1=ch2;
    124                       ch2=tp;
    125                 }
    126                 else
    127                 {
    128                    if(count1>=t1)
    129                 {
    130 
    131                       if(ch1=='E') ch1='N';
    132                       else if(ch1=='N') ch1='W';
    133                       else if(ch1=='S') ch1='E';
    134                       else if(ch1=='W') ch1='S';
    135                       count1=0;
    136                 }
    137                  if(count2>=t2)
    138                 {
    139                       if(ch2=='E') ch2='N';
    140                       else if(ch2=='N') ch2='W';
    141                       else if(ch2=='S') ch2='E';
    142                       else if(ch2=='W') ch2='S';
    143                       count2=0;
    144 
    145                 }
    146                 }
    147 
    148                 //printf("[[%d %d]],[[%d %d]][[%c]]\n",y1,x1,y2,x2,ch2);
    149 
    150           }
    151           printf("%d %d\n%d %d\n",y1,x1,y2,x2);
    152     }
    153     return 0;
    154 }
  • 相关阅读:
    mysql 数据库优化
    eclipse 自动 注释
    rpc 小例子
    几种基于HTTP协议的RPC性能比较
    spring 两个 properties
    xxx.properties获取方法
    Mysql 操作
    Java对象初始化详解
    Tomcat自动启动脚本
    数学工具 在 当代 和 未来 的 进化革命 的 可能性
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2746325.html
Copyright © 2011-2022 走看看