usaco-3.2-spin-pass

模拟题,量不大。

转动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!
时间: 2025-01-11 23:35:52

usaco-3.2-spin-pass的相关文章

Usaco Open09 Gold

Problem 1: Ski Lessons [Brian Jacokes, 2002] Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier. Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Les

【USACO 3.2.3】纺车的轮子

[描述] 一架纺车有五个纺轮,这五个不透明的轮子边缘上都有一些缺口.这些缺口必须被迅速而准确地排列好.每个轮子都有一个起始标记(在0度),这样所有的轮子都可以在统一的已知位置开始转动.轮子按照角度变大的方向旋转(即0经过旋转到达1的位置),所以从起始位置开始,在一定的时间内,它们依次转过1度,2度等等(虽然这些轮子很可能不会同时转过这些角度). 这是一个整数问题.轮子不会转过1.5度或23.51234123度这样的角度.例如,轮子可能在一秒钟内转过20到25度甚至30到40度(如果转得快的话).

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

[usaco3.2.3]spin

这道题直接枚举就好了,但我当时竟然没想到,我真是太失败了.....Q_Q /* ID:abc31261 LANG:C++ TASK:spin */ #include<cstdio> #include<cstring> #include<iostream> using namespace std; const int n=5,maxn=360; int s[10],first[10][10],end[10][10],num[10],f[maxn*2]; bool flag

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

pass语句

Python pass是空语句,是为了保持程序结构的完整性.  pass 不做任何事情,一般用做占位语句. #!/usr/bin/python # -*- coding: UTF-8 -*- # 输出 Python 的每个字母 for letter in 'Python': if letter == 'h': pass print '这是 pass 块' print '当前字母 :', letter print "Good bye!" 执行结果: 当前字母 : P 当前字母 : y 当

USACO Your Ride Is Here

[USACO]Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do,

usaco月赛,2017.1总结

T1:跳舞的奶牛 大致题意:一个体积为k的舞台能够同时容纳k只奶牛一起跳舞,他们每头奶牛的跳舞时间不同,如果有一只奶牛跳完了第k+1头奶牛就会立刻上场跳舞,当所有奶牛跳完舞以后我们认为这次表演结束.现在给出奶牛个数,最多用时,每头奶牛的跳舞时间.求舞台最小为多大. 思路:本来写了个程序以为这道题很简单,刚开始排一下序然后就行了,结果交了以后发现只过了五组,然后才发现这道题不能改变顺序(所以说为什么我改变顺序了还是能过五组,usaco的数据也好水......),所以说我想到了堆,然后就用堆写了一下