码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-3.2-spin-pass

时间:2014-09-12 01:13:42      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   art   div   

    模拟题,量不大。

    转动360秒以后,所有轮子回到起始角度。因此如果360秒以后还没有出现重合情况的话,就可以退出循环了。

    如何判断五个轮子重合呢?起初我也没有很好的方法,一个个去判断重合区域实在是太麻烦了。后来想到一个好方法。把 360度的轮子分成360个区域,用整形数组表示,如果一个轮子的缺口在这个区域内,则这个小区域加1,计算5个轮子的所有缺口。然后遍历这个数组,如果 有个区域的值>=5,表明这个区域上面至少有5个缺口,则5个缺口重合,退出循环。

/*
ID: qq104801
LANG: C++
TASK: spin
*/

#include <iostream>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <algorithm>

using namespace std;

#define PI 360
int speed[6];
bitset<PI> curr[6],next[6];

void test()
{    
    freopen("spin.in","r",stdin);
    freopen("spin.out","w",stdout);
    int num,start,end;
    for(int i=1;i<=5;i++)
    {
        cin>>speed[i]>>num;
        for(int j=1;j<=num;j++)
        {
            cin>>start>>end;
            end+=start;
            for(int k=start;k<=end;k++)
                curr[i].set(k%PI);
        }
    }

    int angle=0;
    bool flag;
    while(angle<PI)
    {
        for(int i=0;i<PI;++i)
        {
            flag=false;
            for(int j=1;j<=5;j++)
                if(!curr[j].test(i))
                {
                    flag=true;
                    break;
                }
            if(!flag)
            {
                cout<<angle<<endl;
                return;
            }    
        }
            
        for(int i=1;i<=5;i++)
        {
            for(int j=0;j<PI;j++)
                next[i][j]=curr[i][(j+PI-speed[i])%PI];
            curr[i]=next[i];
        }
        ++angle;
    }
    cout<<"none"<<endl;
 
}

int main () 
{        
    test();        
    return 0;
}

test data:

USACO Training
Grader Results     
9 users online
CHN/3 IND/1 IRN/1 KGZ/1 ROM/1 USA/1 VNM/1

USER: cn tom [qq104801]
TASK: spin
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.005 secs, 3376 KB]
   Test 2: TEST OK [0.019 secs, 3376 KB]
   Test 3: TEST OK [0.032 secs, 3376 KB]
   Test 4: TEST OK [0.019 secs, 3376 KB]
   Test 5: TEST OK [0.003 secs, 3376 KB]
   Test 6: TEST OK [0.016 secs, 3376 KB]
   Test 7: TEST OK [0.008 secs, 3376 KB]
   Test 8: TEST OK [0.030 secs, 3376 KB]

All tests OK.

YOUR PROGRAM (‘spin‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
30 1 0 120
180 1 10 100
35 1 20 90
31 1 30 80
32 1 50 60
------- test 2 ----
30 1 350 350
180 1 10 100
35 1 67 23
31 1 30 4
32 1 50 7
------- test 3 ----
180 1 0 120
180 1 120 120
180 1 240 120
31 1 30 4
32 1 50 7
------- test 4 ----
1 1 140 359
1 1 200 359
1 1 4 1
2 1 6 1
1 1 300 300
------- test 5 ----
45 5 140 13 300 17 0 15 20 3 40 1
73 1 200 359
105 2 4 1 50 50
179 3 6 1 8 1 359 3
3 1 300 300
------- test 6 ----
45 5 120 13 200 17 0 15 20 3 32 1
73 5 200 100 1 30 50 10 70 2 75 1
105 2 100 1 50 20
179 3 6 1 8 1 359 3
3 1 300 359
------- test 7 ----
73 5 207 101 1 35 57 11 71 2 75 1
45 5 125 13 200 17 0 15 20 3 32 1
96 5 100 12 50 13 0 2 300 39 250 1
119 5 6 1 8 1 359 1 245 1 123 1
15 5 300 1 231 1 185 1 179 2 0 18
------- test 8 ----
73 5 207 11 1 35 57 11 71 2 75 1
45 5 125 3 200 17 0 15 20 3 32 1
96 5 100 1 50 1 0 2 300 39 250 1
119 5 6 1 8 1 359 1 245 1 123 1
15 5 300 1 231 1 185 1 179 2 0 1

Keep up the good work!
Thanks for your submission!

 

usaco-3.2-spin-pass

标签:style   blog   color   io   os   ar   for   art   div   

原文地址:http://www.cnblogs.com/dpblue/p/3967532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!