[Bjwc2008] Qin Teng and teaching evaluation

Source: Internet
Author: User

Doodle

 

Two points.

How can this problem be solved? I didn't come up with it.

I read the question.

Because there is only one odd point, for a position X, the sum of the teachings of the range [0, x] is obtained. If it is an odd number, the value of X is greater; otherwise, X is smaller (wonderful ).

Although the answer is within the int, L + R may blow up the int, resulting in a few points of TLE, so we should open long.

 1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<cctype> 8 #include<vector> 9 #include<stack>10 #include<queue>11 using namespace std;12 #define enter puts("") 13 #define space putchar(‘ ‘)14 #define Mem(a, x) memset(a, x, sizeof(a))15 #define rg register16 typedef long long ll;17 typedef double db;18 const int INF = 0x3f3f3f3f;19 const db eps = 1e-8;20 const int maxn = 2e5 + 5;21 inline ll read()22 {23     ll ans = 0;24     char ch = getchar(), last = ‘ ‘;25     while(!isdigit(ch)) {last = ch; ch = getchar();}26     while(isdigit(ch)) {ans = ans * 10 + ch - ‘0‘; ch = getchar();}27     if(last == ‘-‘) ans = -ans;28     return ans;29 }30 inline void write(ll x)31 {32     if(x < 0) x = -x, putchar(‘-‘);33     if(x >= 10) write(x / 10);34     putchar(x % 10 + ‘0‘);35 }36 37 int n;38 struct Node39 {40     ll s, e, d;41 }t[maxn];42 43 ll calc(ll x)44 {45     ll ret = 0;46     for(int i = 1; i <= n; ++i)47     {48         if(t[i].s > x) continue;49         ret += (min(x, t[i].e) - t[i].s) / t[i].d + 1;50     }51     return ret;52 }53 54 int main()55 {56     int T = read();57     while(T--)58     {59         n = read(); ll Max = 0;60         for(int i = 1; i <= n; ++i) t[i].s = read(), t[i].e = read(), t[i].d = read(), Max = max(Max, t[i].e);61         ll L = 0, R = Max;62         if(!(calc(R) & 1)) {puts("Poor QIN Teng:( "); continue;}63         while(L < R)64         {65             ll mid = (L + R) >> 1;66             if(calc(mid) & 1) R = mid;67             else L = mid + 1;68         }69         write(L), space, write(calc(L) - calc(L - 1)), enter;70     }71     return 0;72 }
View code

 

[Bjwc2008] Qin Teng and teaching evaluation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.