题意:
有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B)。题目保证最多有一个人收到的传单数是奇数。求如果有人收到传单是奇数,输出编号和他收到的传单数。
思路:
观察最后情况,可以发现,要么每个人都是偶数。要么有一个是奇数。观察其前缀和,发现奇数那个人之前的前缀和都是偶数,之后都是奇数。所以,二分之。
代码:
(上交大牛代码……)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std; int n, a[][];
long long sum; bool check(int now){
long long sum = ;
for (int i = ; i <= n; i++)
if (now >= a[i][])
{
int Right = min(a[i][], now);
if (a[i][]) sum += (long long)(Right - a[i][]) / a[i][] + ;
else sum++;
}
return(sum & );
} int read(){
char ch;
for (ch = getchar(); ch < '' || ch > ''; ch = getchar());
int cnt = ;
for (; ch >= '' && ch <= ''; ch = getchar()) cnt = cnt * + ch - '';
return(cnt);
} int main(){
//freopen("j.in", "r", stdin);
//freopen("j.out", "w", stdout);
for (;;)
{
if (scanf("%d", &n) != ) return ;
sum = ;
int Max = ;
for (int i = ; i <= n; i++)
{
a[i][] = read(); a[i][] = read(); a[i][] = read();
if (a[i][]) sum += (long long)(a[i][] - a[i][]) / a[i][] + ;
else sum++;
Max = max(Max, a[i][]);
}
if (!(sum & ))
{
printf("DC Qiang is unhappy.\n");
continue;
}
long long Left = , Right = Max, Mid = (Left + Right) >> ;
while (Left + < Right)
{
if (check(Mid)) Right = Mid;
else Left = Mid;
Mid = (Left + Right) >> ;
}
printf("%d", Right);
int cnt = ;
for (int i = ; i <= n; i++)
if (Right >= a[i][] && Right <= a[i][] && !((Right - a[i][]) % a[i][])) ++cnt;
printf(" %d\n", cnt);
}
}