Problem Description
The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part
of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i,
A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that
we can comfort him by treating him to a big meal!
Input
There are multiple test cases. For each test case, the first line contains a number N (0 < N <= 20000) indicating the number of societies. Then for each of the following N lines, there are three non-negative integers A_i, B_i, C_i (smaller than 2^31, A_i <=
B_i) as stated above. Your program should proceed to the end of the file.
Output
For each test case, if there is no unlucky student, print "DC Qiang is unhappy." (excluding the quotation mark), in a single line. Otherwise print two integers, i.e., the label of the unlucky student and the number of flyers he/she gets, in a single line.
Sample Input
2 1 10 1 2 10 1 4 5 20 7 6 14 3 5 9 1 7 21 12
Sample Output
1 1 8 1
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long a[20000];
long long b[20000];
long long c[20000];
int n;
long long check(long long mid)
{
long long sum=0,k;
int i;
for(i=0;i<n;i++)
{
k=min(b[i],mid);
if(k>=a[i])
{
sum+=(k-a[i])/c[i]+1;
}
}
return sum;
}
int main(int argc, char *argv[])
{
while(scanf("%d",&n)!=EOF)
{
int i;
for(i=0;i<n;i++)
{
scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
}
long long l=0,r=2147483648;
long long mid=0;
while(l<r)
{
mid=(l+r)/2;
if(check(mid)%2==1)
{
r=mid;
}
else
{
l=mid+1;
}
}
if(l==2147483648)
printf("DC Qiang is unhappy.\n");
else
{
while(check(l)%2==0)l--;
printf("%lld %lld\n",l,check(l)-check(l-1));
}
}
return 0;
}
在一个新学期开始之际,多个学生社团通过发放传单来吸引新成员。由于资金限制,每个社团只能向部分学生发放传单。本问题探讨如何确定是否有且仅有一个学生收到奇数张传单,并找出这名学生的编号及所收传单的数量。
523

被折叠的 条评论
为什么被折叠?



