Spinning Wheels
1998 ACM NE Regionals

Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an alignment mark (at 0 degrees) so that the wheels can all be started in a known position. Wheels rotate in the `plus degrees' direction, so that shortly after they start, they pass through 1 degree, 2 degrees, etc. (though probably not at the same time).

This is an integer problem. Wheels are never actually at 1.5 degrees or 23.51234123 degrees. For example, the wheels are considered to move instantaneously from 20 to 25 degrees during a single second or even from 30 to 40 degrees if the wheel is spinning quickly.

All angles in this problem are presumed to be integers in the range 0 <= angle <= 359. The angle of 0 degrees follows the angle of 359 degrees. Each wheel rotates at a certain integer number of degrees per second, 1 <= speed <= 180.

Wedges for each wheel are specified by an integer start angle and integer angle size (or `extent'), both specified in degrees. Wedges in the test data will be separated by at least one degree. The 'extent' also includes the original "degree" of the wedge, so '0 180' means degrees 0..180 inclusive -- one more than most would imagine.

At the start, which is time 0, all the wheels' alignment marks line up. Your program must determine the earliest time (integer seconds) at or after the start that some wedge on each wheel will align with the wedges on the other wheel so that a light beam can pass through openings on all five wedges. The wedges can align at any part of the rotation.

PROGRAM NAME: spin

INPUT FORMAT

Each of five input lines describes a wheel.

The first integer on an input line is the wheel's rotation speed. The next integer is the number of wedges, 1 <= W <= 5. The next W pairs of integers tell each wedge's start angle and extent.

SAMPLE INPUT (file spin.in)

  1. 30 1 0 120
  2. 50 1 150 90
  3. 60 1 60 90
  4. 70 1 180 180
  5. 90 1 180 60

OUTPUT FORMAT

A single line with a single integer that is the first time the wedges align so a light beam can pass through them. Print `none' (lower case, no quotes) if the wedges will never align properly.

SAMPLE OUTPUT (file spin.out)

  1. 9

一架纺车有五个纺轮(也就是五个同心圆),这五个不透明的轮子边缘上都有一些缺口。这些缺口必须被迅速而准确地排列好。每个轮子都有一个起始标记(在0度),这样所有的轮子都可以在统一的已知位置开始转动。轮子按照角度变大的方向旋转(即0经过旋转到达1的位置),所以从起始位置开始,在一定的时间内,它们依次转过1度,2度等等(虽然这些轮子很可能不会同时转过这些角度)。

这是一个整数问题。轮子不会转过1.5度或23.51234123度这样的角度。例如,轮子可能在一秒钟内转过20到25度甚至30到40度(如果转得快的话)。

这个问题中的所有角度都限制在 0 <= 角度 <= 359 这个范围内。轮子转过 359 度后接下来就是 0 度。每个轮子都有一个确定的旋转速度,以秒作为单位。1 <= 速度 <= 180。

轮子上的缺口的起始角度和缺口大小(或宽度)各由一个整数表示,都以度为单位。在一个轮子上,两个缺口之间至少有一度的间隔。宽度也包含缺口起始的角度,即0 180包括0..180共计181个角度,比一般人想象的多一个。

在起始位置,设时间为 0,所有的轮子的起始标记排列成一条直线。你的程序必须计算,最早出现每个的轮子上的缺口同其他轮子上的缺口对准(也就是一束光可以通过五个轮子上的五个缺口)情况的时间。这些缺口在任意一个角度对准。

bitset版本:

  1. /*
  2. ID: LinKArftc
  3. PROG: spin
  4. LANG: C++
  5. */
  6.  
  7. #include <map>
  8. #include <set>
  9. #include <cmath>
  10. #include <stack>
  11. #include <queue>
  12. #include <vector>
  13. #include <cstdio>
  14. #include <string>
  15. #include <bitset>
  16. #include <utility>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <iostream>
  20. #include <algorithm>
  21. using namespace std;
  22. #define eps 1e-8
  23. #define randin srand((unsigned int)time(NULL))
  24. #define input freopen("input.txt","r",stdin)
  25. #define debug(s) cout << "s = " << s << endl;
  26. #define outstars cout << "*************" << endl;
  27. const double PI = acos(-1.0);
  28. const int inf = 0x3f3f3f3f;
  29. const int INF = 0x7fffffff;
  30. typedef long long ll;
  31.  
  32. int speed[];
  33.  
  34. int main() {
  35. freopen("spin.in", "r", stdin);
  36. freopen("spin.out", "w", stdout);
  37. bitset <> now[], tmp[];
  38. for (int i = ; i <= ; i ++) {
  39. int x;
  40. scanf("%d %d", &speed[i], &x);
  41. int s, t;
  42. for (int j = ; j <= x; j ++) {
  43. scanf("%d %d", &s, &t);
  44. t += s;
  45. for (int k = s; k <= t; k ++) now[i].set(k % );
  46. }
  47. }
  48. for (int k = ; k < ; k ++) {
  49. for (int i = ; i < ; i ++) {
  50. bool flag = false;
  51. for (int j = ; j <= ; j ++) {
  52. if (!now[j].test(i)) {
  53. flag = true;
  54. break;
  55. }
  56. }
  57. if (!flag) {
  58. printf("%d\n", k);
  59. return ;
  60. }
  61. }
  62. for (int i = ; i <= ; i ++) {
  63. for (int j = ; j < ; j ++) {
  64. tmp[i][j] = now[i][(j + - speed[i]) % ];
  65. }
  66. now[i] = tmp[i];
  67. }
  68. }
  69. printf("none\n");
  70.  
  71. return ;
  72. }

spin_USACO的更多相关文章

随机推荐

  1. 在临床医学里面,bid、tid、qid和q3w是什么意思啊??这些缩写的全称是怎么写呢??

    { value: 'QD', name: 'QD 每日一次' }, { value: 'BID', name: 'BID 每日两次' }, { value: 'TID', name: 'TID 每日三 ...

  2. Redis架构演变与redis-cluster群集读写方案

    导言 redis-cluster是近年来redis架构不断改进中的相对较好的redis高可用方案.本文涉及到近年来redis多实例架构的演变过程,包括普通主从架构(Master.slave可进行写读分 ...

  3. 第49天:封装自己的scrollTop

    一.scroll家族 offset 自己的偏移scroll滚动的 scrollTop和scrollLeftscrollTop 被卷去的头部当滑动滚轮浏览网页的时候,网页隐藏在屏幕上方的距离二.页面滚动 ...

  4. matlab exist函数

    函数作用:用于确定某变量或值是否存在. 调用格式: exist主要有两种形式,一个参数和两个参数的,作用都是用于确定某值是否存在:1. b = exist( a) 若 a 存在,则 b = 1: 否则 ...

  5. mac终端命令-----常规操作

    OSX 的文件系统 OSX 采用的Unix文件系统,所有文件都挂在跟目录 / 下面,所以不在要有Windows 下的盘符概念. 你在桌面上看到的硬盘都挂在 /Volumes 下. 比如接上个叫做 US ...

  6. 【bzoj1821】[JSOI2010]Group 部落划分 Group Kruskal

    题目描述 聪聪研究发现,荒岛野人总是过着群居的生活,但是,并不是整个荒岛上的所有野人都属于同一个部落,野人们总是拉帮结派形成属于自己的部落,不同的部落之间则经常发生争斗.只是,这一切都成为谜团了——聪 ...

  7. Django 2.0 学习(09):Django 静态文件(样式和背景图片)

    应用的定制化:静态文件 首先,在polls目录中创建一个名叫static的目录.Django会在该目录里面查找静态文件,类似于Django在polls/template目录下查找模板文件. Djang ...

  8. OI入门

    学习顺序: 1.高精度计算: 高精度计算(一) 高精度计算练习1 高精度计算(二) 高精度计算练习2 2.递推 3.递归 递归算法 递归练习 4.搜索与回溯 搜索与回溯算法(一) 搜索与回溯练习(一) ...

  9. [NOI2017]蔬菜 贪心

    题面: [NOI2017]蔬菜 题解: 首先每天蔬菜会变质这点并不好处理,我们考虑让时间倒流,从后向前处理,这样的话就相当于每天都会得到一定量的蔬菜. 这样做有什么好处呢? 我们可以发现一个性质:如果 ...

  10. Windows相关

    PE WIndows 相关知识 windows 主机防护