10.31 NOIP simulation race (Morning)

2023-01-02   ES  


Time Limit:1000ms Memory Limit:64MB

Question description

lyk likes to study some difficult problems, such as NP issues. 
 This time it encountered another tricky NP problem. The problem is like this: there are two numbers n and p, find the step of n 
 The result of picker p. 
 LYK thinks all NP problems are algorithm without polynomial complexity, so it intends to ask for help to participate in NOIP 
 You, help LYK!

Input format (np.in)

Input a line of two integer n, p.

output format (np.out)

Output a line of an integer to represent the answer.

Input sample

3 4

output sample


data range

For 20%data: n, p <= 5. 
 For 40%data: n, p <= 1000. 
 For 60%data: n, p <= 10000000. 
 For 80%data: n <= 10^18, P <= 10000000. 
 For another 20%data: n <= 10^18, P = 10000007. 
 Of these, 50%of the data meets n> = p.


Blocking Table 
 All K!, Where K Mod 10000000 = 0. Find the known answer directly when you ask, and you can find the answer without more than 100,000.


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
long long n,p;
long long now;
const int a[100]={
const int MOD=1000000007;
int main()
    if (p==1000000007)
        if (n>=p) {
   puts("0"); return 0;}if (n<10000000) now=1; else now=a[n/10000000-1];
        for (int i=n/10000000*10000000+1; i<=n; i++) now=now*i%MOD;
    } else
        if (n>=p) now=0; else for (int i=1; i<=n; i++) now=now*i%p;
    return 0;

Look at the program writing results (Program)

Time Limit:1000ms Memory Limit:64MB


lyk is currently preparing NOIP2017's preliminary round. What is the least good at is to see the program and write the results, so it desperately 
 This time it gets such a program: 
 Readln (n); 
 for i: = 1 to n do read (a [i]); 
 For I: = 1 to n do for j: = 1 to n do for k: = 1 to n do for l: = 1 to n down 
 if (a [i] = a [j]) and (a [i] <a [k]) and (a [k] = a [l]) then ans: = (ang 1) MOD 1000000007; 
 writeln (ANS); 

 C ++: 
 scanf ("%d", & n); 
 for (i = 1; i <= n; i ++) scanf ("%d", & a [i]); 
 For (i = 1; i <= n; i ++) for (j = 1; j <= n; j ++) for (k = 1; k <= n; k ++) for (l = 1; l <= n; L ++) 
 if (a [i] == a [j] && a [i] <a [k] && a [k] == a [l]) ans = (ang 1)%1000000007; 
 Printf ("%d \ n", ANS); 
 LYK knows all the input data, and it wants to know how much this program runs.

Input format (Program.in)

The first line of the number n, the second line n, represent AI.

output format (program.out)

A number indicates the answer.

Input sample

1 1 3 3

output sample


Data range

For 20%data n <= 50. 
 For 40%data n <= 200. 
 For 60%data n <= 2000. 
 For 100%data n <= 100000, 1 <= AI <= 1000000000. 
 Among them, 50%of the number of AIs with different data <= 10 is evenly distributed, and the number of AIs with different data of 50%of the data> = n/10.


The principle of multiplication is used 
 Sort the AI first. 
 Let f [i] represent the same AI pair in 1 ~ i. 
 For the position of all AI! = A {i+1}, the f [i]*g*(g-1)/2 is added into the answer. G represents how much number exists = a {i+1}. 
 Time complexity NLGN.


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long ans,f[100005];
int i,n,a[100005],sum;
const int MOD=1000000007;
int cmp(int i,int j) {
   return i<j;}
int main()
    for (i=1; i<=n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp); sum=1; f[1]=1;
    for (i=2; i<=n; i++)
        if (a[i]==a[i-1])
            f[i]=f[i]-1ll*sum*sum; sum++;
        } else {
   sum=1; f[i]++;}
    for (i=n; i>=2; i--)
        if (a[i]==a[i+1]) sum++; else sum=1;
        if (a[i]!=a[i-1]) ans=(ans+f[i-1]*sum%MOD*sum)%MOD;
    return 0;

Select numbers (Select)

Time Limit:3000ms Memory Limit:64MB

Title description

lyk found a matrix of N*M. There are some numbers on this matrix. 
 The number is AI, J. 
 Because it was AK's preliminary round of NOIP2016, it seemed very boring recently, and I thought of a way to entertain and entertain it. 
 The game it thinks is like this: every time you choose one or a column, the happiness value it gets will be this line or a column 
 The sum of numbers. After that, it subtracted the number of the line or on the column (may be turned into negative numbers later). So, repeat K K 
 Second, the sum of the happiness it gets will be its NOIP2016 rematch. 
 Lyk certainly wants its RP value to be as high as possible, so it will help you.

Input format (Select.in)

The first line of 4 numbers n, m, k, p. 
 Next N line M column, representing AI, J.

output format (Select.out)

Output a line represents the maximum RP value.

Input sample

2 2 5 2
1 3
2 4

output sample


Data range

A total of 10 sets of data. 
 For groups 1, 2 data n, m, k <= 5. 
 For the third group of data K = 1. 
 For the 4th group of data p = 0. 
 For groups 5,6 data n = 1, m, k <= 1000. 
 For group 7,8 data n = 1, m <= 1000, k <= 1000000. 
 For all data 1 <= n, m <= 1000, K <= 1000000, 1 <= AI, J <= 1000, 0 <= P <= 100.

Sample Explanation

Choose the second column for the first time, the second line of the second line, the third time the first line, the second line of the second line, the fifth 
 Select the first line, the happiness value is 7+4+2+0+-2 = 11.


The order of choice is irrelevant. Assuming that we chose line X, then the K-X column must be selected. 
 Let f [i] indicate the maximum sum to choose I. Consider how to find all f [i]. 
 This is obviously greedy. Record the sum of all lines. Just use the big roots to maintain. 
 Let G [i] indicate the maximum selection of I column. Known F and G. 
 The answer is Max {f [i]+g [k-i] -I*(k-I)*p).


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1000005;
long long ans,s1[N],s2[N],p1[N],p2[N];
int k,n,m,i,j,p,A;
int cmp(int i,int j) {
   return i<j;}
int main()
    for (i=1; i<=n; i++)
        for (j=1; j<=m; j++)
        s1[i]+=A; s2[j]+=A;
    for (i=1; i<=k; i++)
    for (i=0; i<=k; i++) {ans=max(ans,p1[i]+p2[k-i]-1ll*i*(k-i)*p);}
    return 0;


Random Posts

JS SLICE, SUBSTRING and SUBSTR differences zhongjian

Linux, Window Compile Quazip and Test

chain table operation set Dilly

Calculation advertisement/Digital marketing Frequently Term XURUI

Bugkuctf-WEB Title Ex-Girlfriend Binbin is polite AM