August 10 summary

CYJian candy solving report


Topics are as follows:

He now has $ $ n-bulk candies, each bulk candies $ r [i] -l [i] + 1 $ small piece of candy, sweet confection pieces of each of l [i], l [i] + 1, l [i] +2 ...... r [i].

He can now optionally from each large candy to a small confectionery composition candy his platter, sweet elected set of candy is x [1], x [2 ] ..... x [n], provided .

The definition of candy platter happiness index .

Now CYJian want to ask you, the happiness index of all programs he selected platter and how much? (Results output answer modulo 1e9 + 7)

Input of the first line of a positive integer n, the number of bulk candies

Next n lines of a l [i], r [i], the output of a number of answers.

Sample Input 1: 3,112,311 Sample Output 1:13

2 Sample input: 3,252,425 Output Sample 2: 282


PS:  express

ans=1;
forint i=1;i<=n;i++)
    ans*=(h-x[i]+1);

 Math question? ? ? ?

Push teacher in the class for two hours a formula hhhh

In a nutshell is the maximum number (that is, h) the same into the same category

And must contain a Category 1, when excluding one not in line with the meaning of problems (because of their own +1 maximum minus 1)

Example:

If there are two big candy, candy and small are 1,2,3

So what if all the points are connected, with a total of nine categories, of which only five kinds of questions intended to meet the

In all cases with the calculation by subtracting non-compliance with better count

Figure (marked red is in line with the meaning of problems):

I.e., operation of (pseudo): sum ([1,3]) - sum ([2,3]).

Then the maximum value of each of different situations can be summed% mod


Important!

Since the subject of the request to take the tired, so the answer may be very large (the title requires% 1000000007 teacher said is out of question people we would not write high-precision )

Generally speaking, in the process of addition and subtraction multiplication in one side (ans% mod + mod)% mod is not a problem

But if the change in the division in addition to the operational change will lead to wrong answer, so pay special attention to the problems in the process of writing


Code:

 1 #include<bits/stdc++.h>
 2 #define mod 1000000007
 3 #define Freopen(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
 4 using namespace std;
 5 int n;
 6 long long Maxl,Maxr,ans;
 7 long long l[1005],r[1005];//不开longlong见zs 
 8 long long solve(long long a1,long long a2){
 9     long long ret=1 ; // Since multiplication is tired, it is initialized to 1 
10      for ( int I = 1 ; I <= n-; I ++) { // n-large candy 
. 11          Long  Long RR = min (R & lt [I], A1) ; // find the maximum value, i.e. H 
12 is          Long  Long SUM = (RR-L [I] + . 1 )% * MOD (L [I] + RR) / 2 % MOD; // addition to extra part and% Note
 13          // here sum = x [1] + x [2] + ... x [n] ( the first item plus the last item by item number divided by 2) 
14          SUM = (((RR-L [I] + . 1 )% * MOD (A2 + . 1 )% MOD-SUM) + MOD% MOD)% MOD;
 15          // here sum = the selected degree multiplicative candy sweet 
16         ret=(ret*sum)%mod;
17     }
18     return ret;
19 }
20 int main(){
21     Freopen(a);
22     scanf("%d",&n);
23     for(int i=1;i<=n;i++){
24         scanf("%d%d",&l[i],&r[i]);
25         Maxl=max(Maxl,l[i]),Maxr=max(Maxr,r[i]);//找出r,l中的最大值 
26     }
27     for(int= maxL I; I <= MAXR; I ++ ) {
 28          Long  Long tmp = ((Solve (I, I) -solve (I- . 1 , I)) +% MOD MOD) MOD%; // for different situations operation 
 29          // Solve (I, I) in the embodiment corresponds to the sum ([1,3]), solve ( i-1, i) in the embodiment corresponds to the sum ([2,3]) 
30          ANS = (ANS tmp +)% MOD;
 31 is      }
 32      the printf ( " % LLD " , ANS);
 33 is      return  0 ;
 34 is }

Summary: look at the code is actually quite simple

But for such a strong mathematical problems, with emphasis on their own can not think of 8 Anyway, I did not expect

In fact, things are above analysis of the teacher in the class hhhh rain I have no melon

Guess you like

Origin www.cnblogs.com/Yz-jw/p/11332993.html