spin_USACO
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)
30 1 0 120
50 1 150 90
60 1 60 90
70 1 180 180
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)
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版本:
/*
ID: LinKArftc
PROG: spin
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; int speed[]; int main() {
freopen("spin.in", "r", stdin);
freopen("spin.out", "w", stdout);
bitset <> now[], tmp[];
for (int i = ; i <= ; i ++) {
int x;
scanf("%d %d", &speed[i], &x);
int s, t;
for (int j = ; j <= x; j ++) {
scanf("%d %d", &s, &t);
t += s;
for (int k = s; k <= t; k ++) now[i].set(k % );
}
}
for (int k = ; k < ; k ++) {
for (int i = ; i < ; i ++) {
bool flag = false;
for (int j = ; j <= ; j ++) {
if (!now[j].test(i)) {
flag = true;
break;
}
}
if (!flag) {
printf("%d\n", k);
return ;
}
}
for (int i = ; i <= ; i ++) {
for (int j = ; j < ; j ++) {
tmp[i][j] = now[i][(j + - speed[i]) % ];
}
now[i] = tmp[i];
}
}
printf("none\n"); return ;
}
spin_USACO的更多相关文章
随机推荐
- Android各分辨率定义的图片规格
我们定义的app图片规格 app图标需要分iphone和android两套 iphone: 名称 Iphone4 Iphone5 手机尺寸 960*640(高*宽) 1136*640 (高*宽) 电池 ...
- Apache Tomcat Nginx的区别和联系
一.定义 1. Apache Apache HTTP服务器是一个模块化的服务器,可以运行在几乎所有广泛使用的计算机平台上.其属于应用服务器.Apache支持支持模块多,性能稳定,Apache本身是静态 ...
- 第27天:js-表单获取焦点和数组声明遍历
一.表单 1.this指事件的调用者2.input.value 表单更换内容3.innerHTML更换盒子里的内容,文字.标签都能换.4.isNaN("12")如果里面的不是个数字 ...
- 【bzoj1704】[Usaco2007 Mar]Face The Right Way 自动转身机 贪心
题目描述 农夫约翰有N(1≤N≤5000)只牛站成一排,有一些很乖的牛朝前站着.但是有些不乖的牛却朝后站着.农夫约翰需要让所有的牛都朝前站着.幸运的是约翰最近买了一个自动转身机.这个神奇的机器能使K( ...
- Go语言【第六篇】:Go循环语句
Go语言循环语句 在不少实际问题中有许多具有规律性的重复操作,因此在程序中就需要重复执行某些语句,以下为大多数编程语言循环程序的流程如: Go语言提供了以下几种类型循环处理语句: 循环类型 描述 fo ...
- Ubuntu 10.04 下载android 4.1.1_r4
一.安装 curl git $ sudo apt-get install curl $ sudo apt-get install git-core 二.安装repo 1.在主目录(~)建立目录 bi ...
- [NOI.AC省选模拟赛3.31] 附耳而至 [平面图+最小割]
题面 传送门 思路 其实就是很明显的平面图模型. 不咕咕咕的平面图学习笔记 用最左转线求出对偶图的点,以及原图中每个边两侧的点是谁 建立网络流图: 源点连接至每一个对偶图点,权值为这个区域的光明能量 ...
- 专题训练之2-sat
推荐几篇博客:https://blog.csdn.net/JarjingX/article/details/8521690 研究总结2-sat问题 https://blog.csdn.net/wher ...
- 第一章 深入web请求过程
B/S架构的的好处: 客户端使用统一的浏览器(browser).由于浏览器的统一性,它不需要特殊的配置和网络连接,有效的屏蔽了不同服务提供商提供给用户使用服务的差异性.另外一点是浏览器的交互特性使得用 ...
- Mybatis(1) 创建Mybatis HelloWorld
简介: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 ...