Alien Sunset

Description

Following tremendous advances in space flight control software and equally impressive innovations in reality TV crowdfunding, humans have successfully settled a number of planets, moons, asteroids, and various other kinds of funny-shaped rocks across our solar system.

To celebrate, the Galactic President has elected to create a new holiday called "Solar Night". At the crux of the event, she decrees, every settlement will simultaneously launch colourful fireworks into the darkness of night.

Night, like most things, is a difficult problem in space. Every spacebound object has its own day length and period of rotation. Thankfully all of the settlements did, at least, start their clocks at the same moment. Settlements may have started in daylight or darkness and so it is possible that the first recorded sunrise can be either before or after the first hour of sunset.

By convention, the President’s term lasts for exactly 1825 days as measured by the planet with the longest period of rotation. The celebration needs to happen within that time or it will not serve its intended purpose.

Determine how many hours must pass for us to find a suitable time to celebrate Solar Night.

Input

• One line containing the integer N (1 ≤ N ≤ 20), the number of settlements.

• N lines, each containing three integers:

           – H (2 ≤ H ≤ 100), the number of hours in this settlement’s solar day.

     – R and T (0 ≤ R,T ≤ H −1,R 6= T), the hours of sunrise and sunset respectively. 

At sunrise and sunset, a settlement is in darkness. At times strictly in between sunrise and sunset, a settlment is in daylight.

Output

Output the number of hours that must pass from when the settlement clocks began until each settlement is in darkness. If no suitable time occurs in the first 1825 days,output impossible.

Sample Input

2

24 7 19

24 18 6

Sample Output

6

Sample Input

3

10 8 2

15 5 10

20 15 10

Sample Output

12

Sample Input

2

6 4 2

12 7 5

Sample Output

impossible

Sample Input

2

10 5 6

10 6 5

Sample Output

5

题解:计算n个星球同是黑夜的时刻,遍历一遍就好了。

代码如下:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
long long int q[511][511]= {0};
struct pop
{
    long long int x,y,z;
} s[501];
int main()
{
    long long int m,n,max=0;
    cin>>n;
    for(long long int i=0; i<n; i++)
    {
        cin>>s[i].x>>s[i].y>>s[i].z;
        if(i==0)
            max=s[0].x;
        if(max<s[i].x)
            max=s[i].x;
        long long int k=0;
        if(s[i].y>s[i].z)
            k++;
        for(long long int j=0; j<s[i].x; j++)
        {
            if(k!=0)
                if(s[i].y<j||s[i].z>j)
                    q[i][j]=1;
                else
                    q[i][j]=0;
            else
            {
                if(j>s[i].y&&j<s[i].z)
                    q[i][j]=1;
                else
                    q[i][j]=0;
            }
        }
    }
    long long int i;
    for(i=0; i<=max*1258; i++)
    {
        long long int ss=0;
        for(long long int j=0; j<n; j++)
        {
            ss+=q[j][i%s[j].x];
        }
        if(ss==0)
            break;
    }
    if(i==max*1258+1)
        cout<<"impossible"<<endl;
    else
        cout<<i<<endl;
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值