题意:给定五个同心圆,每个同心圆上有数个齿轮(整数角度)且有一定的转速,问你多少秒以后能够使得一条直线直接射到圆心

解题思路:模拟,每个圆的最大周期就是360;

解题代码:

  1 // File Name: spin.c
  2 // Author: darkdream
  3 // Created Time: 2014年03月03日 星期一 19时14分20秒
  4 /*
  5 ID: dream.y1
  6 PROG: spin
  7 LANG: C++
  8 */
  9 #include<stdio.h>
 10 #include<string.h>
 11 #include<stdlib.h>
 12 #include<time.h>
 13 #include<math.h>
 14 
 15 struct node{
 16   int x, y ; 
 17 }map[6][100];
 18 int num[100];
 19 int speed[100];
 20 int yes(int x, int p )
 21 {
 22    if(p == 6 )
 23        return 1 ;
 24    
 25    for(int j = 1;j <= num[p]; j ++)
 26    {
 27        if(map[p][j].y < map[p][j].x )
 28        {
 29           if(!(x >map[p][j].y && x < map[p][j].x))
 30              return  yes(x,p+1);
 31 
 32        }else {
 33           if(x >= map[p][j].x  && x <= map[p][j].y)
 34             return   yes(x,p+1);
 35        } 
 36    }
 37   // printf(" %d %d\n",x,p);
 38    return 0 ;
 39     
 40 }
 41 void test()
 42 {
 43             for(int j = 1;j <= 5;j ++)
 44             {    for(int s = 1; s <= num[j] ;s ++)
 45                 {
 46                    printf("%d %d** ",map[j][s].x,map[j][s].y );
 47 
 48                 }
 49                 printf("\n");
 50             
 51             }
 52 
 53 }
 54 int ifok()
 55 {
 56     for(int i = 0 ;i <= 360;i ++)
 57         if(yes(i,1))
 58         {  
 59             return 1; 
 60         }
 61     return 0 ; 
 62 
 63 }
 64 void dospeed()
 65 {
 66   for(int i =1;i <= 5;i ++)
 67   {
 68      for(int j =1;j <= num[i];j ++)
 69      {
 70         map[i][j].x  = (map[i][j].x + speed[i] ) % 360 ;
 71         map[i][j].y  = (map[i][j].y + speed[i] ) % 360 ;
 72      }
 73   }
 74 }
 75 void init()
 76 {
 77   memset(map,0,sizeof(map));
 78   memset(num,0,sizeof(num));
 79   memset(speed,0,sizeof(speed));
 80 }
 81 int main(){
 82     freopen("spin.in","r",stdin);
 83     freopen("spin.out","w",stdout);
 84   init();
 85   for(int i = 1;i <= 5;i ++)
 86   {
 87       scanf("%d %d",&speed[i],&num[i]);
 88       for(int j  =1 ;j  <= num[i] ;j ++)
 89         {
 90           scanf("%d %d",&map[i][j].x,&map[i][j].y);
 91           map[i][j].y = (map[i][j].x + map[i][j].y) % 360;
 92         }
 93   }
 94   //int ok = 0;
 95   int time = 0 ;
 96   
 97   if(ifok())
 98   {
 99      printf("0\n");
100      return 0;
101   }
102   while(1)
103   {
104     //if(time == 0)
105     //    test();
106     time ++ ; 
107     dospeed();
108     if(ifok())
109         break;
110     if(time > 400)
111         break;
112   }
113   if(time <= 400)
114       printf("%d\n",time);
115   else printf("none\n"); 
116 return 0 ;
117 }    
View Code

 

posted on 2014-03-17 20:59  dark_dream  阅读(406)  评论(0编辑  收藏  举报