Codeforces Gym101606 A.Alien Sunset (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

寒假第一次组队训练赛,和学长一起训练,题目难度是3颗星,我和猪队友写了6题,第二次训练赛,题目难度2颗星,写出了8道题,两次比赛都不是第一,差一点,很伤。

这是第一次训练的题解,第二次的在上一篇博客,本来不想今天写题解的,但是明天又有新的训练。

写吧写吧,谁让我是最菜的(;´д`)ゞ,随便写写,头疼。。。因为是PDF的题目,不贴题目了,直接上代码。。。

A Alien Sunset

这个题是日出日落的,不是我写的,猪队友写的,贴他的代码。

代码:(猪的)

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <string.h>
 4 #include <stdlib.h>
 5 #include <iostream>
 6 #include <sstream>
 7 #include <algorithm>
 8 #include <string>
 9 #include <queue>
10 #include <map>
11 #include <vector>
12 using namespace std;
13 const int maxn = 1e6+10;
14 const int maxm = 1e4+10;
15 const int inf = 0x3f3f3f3f;
16 const double epx = 1e-10;
17 typedef long long ll;
18 const ll INF = 1e18;
19 struct node
20 {
21     int d,h,r;
22     int l;
23 }a[maxn];
24 int b[maxn][20];
25 int n;
26 int main()
27 {
28     cin>>n;
29     int maxx=0;
30     for(int i=1;i<=n;i++)
31     {
32         cin>>a[i].d>>a[i].h>>a[i].r;
33         a[i].l=a[i].d;
34         maxx=max(maxx,a[i].d);
35     }
36     for(int i=0;i<maxx*1825;i++)
37     {
38         for(int j=1;j<=n;j++)
39         {
40             if(i>a[j].d-1)
41             {
42                 a[j].d+=a[j].l;
43                 a[j].h+=a[j].l;
44                 a[j].r+=a[j].l;
45             }
46             if(a[j].h<a[j].r)
47             {
48                 if(i>a[j].h&&i<a[j].r)
49                     b[i][j]=1;
50                 else
51                     b[i][j]=2;
52             }
53             else
54             {
55                 if(i>=a[j].r&&i<=a[j].h)
56                     b[i][j]=2;
57                 else
58                     b[i][j]=1;
59             }
60         }
61     }
62     int ans=-1;
63     for(int i=0;i<maxx*1825;i++)
64     {
65         int sum=0;
66         for(int j=1;j<=n;j++)
67         {
68             if(b[i][j]==2)
69                 sum++;
70         }
71         if(sum==n)
72         {
73             ans=i;
74             break;
75         }
76     }
77     if(ans!=-1)
78         printf("%d
",ans);
79     else
80         printf("impossible
");
81 }
原文地址:https://www.cnblogs.com/ZERO-/p/8353750.html