test20190611 NOIP simulation game

A question: answer game

[Problem Description]
YYH enrolled in a special television quiz shows. After the show there are n questions, each correct answer a question, YYH will get 1 point, and whenever k YYH answer questions in a row, then his existing score multiplied by 2, pay attention to the k-answer questions, is to add 1 assigned score, the score and then multiplied by 2, then the counter is cleared successive correct answers. Now the success of the YYH m title, he wanted to know his youngest scoring. Because this number may be large, you only need to output the results to the modulo number of 1,000,000,009.

[Input format
only one row, three numbers n, m, k as described in the title.

[] Output format
is only one line, a number, YYH minimum score.

Sample 1 [O]
exam.in
. 5 2. 3
exam.out
. 3

Sample 2 [O]
exam.in
. 5. 4 2
exam.out
. 6

[Explain] Sample
Sample 1, 3, 5 questions answered correctly can get the lowest score 3 points;
Sample 2 wrong answer to question 4, you can get the lowest score 4 + 2 points.

[Data range]
for 30% of data, n, m, k <= 10
to 60% of the data, n, m, k <= 1000
to 100% of the data, 2 <= k <= n <= 10 ^ 9 , 0 <= m <= n



This is clearly a priority to put back the k-1 a space. Then in front of you is not enough to put on the line in a row. This conclusion is very simple to prove.

It did not take the mold, and then there are in addition to 0 ...... but I do not want to write the number of columns or recursive matrix multiplication, so TLE two points.

#include<bits/stdc++.h>
#define co const
template<class T>T read(){
    T data=0,w=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-') w=-w;
    for(;isdigit(ch);ch=getchar()) data=data*10+ch-'0';
    return data*w;
}
template<class T>T read(T&x){
    return x=read<T>();
}
typedef long long ll;
using namespace std;

co int mod=1e9+9;
int mul(int x,int y){
    return (ll)x*y%mod;
}
int add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
int main(){
    freopen("exam.in","r",stdin),freopen("exam.out","w",stdout);
    int n=read<int>(),m=read<int>(),k=read<int>();
    int t=k>1?min(n-m,min(n/k,m/(k-1))):0;
    m-=t*(k-1);
    int ans=0;
    for(;m;m-=k){
        if(m<k){
            ans=add(ans,m);
            break;
        }
        ans=mul(2,add(ans,k));
    }
    printf("%d\n",add(ans,t*(k-1)));
    return 0;
}

Question two: the human genome

[Problem Description]
Professor L recently working on a project on human genes, which can be viewed as a sequence of length n: A0, A1, ......, An -1. After the gene sequence for the k-bit cyclic shift, we can get a new gene sequence is: Ak, Ak + 1, ... , An-1, A0, A1, ..., Ak-1. When a gene sequence to meet before any i (1 <= i <= n) and the items is not less than 0 is satisfied, we say that the gene sequence is gene sequence quality.
Due to the recent work of Professor L busy, so being found wandering in your lab, your task is to help the statistics of the number of L professors all high-quality gene sequence.

[Input format
of the first line of an integer n, denotes the length of the gene sequences.
The second line n integers, followed by A0, A1, ......, An- 1 value.

[] Output format
outputs only an integer representing the number of high-gene sequence.

Sample 1 [O]
genes.in
. 3
2 2. 3
genes.out
. 3

[Sample 1] described
sequence of three elements: 223, cyclic shift as follows:
cyclic shift sequences obtained 0: 223, respectively, and the former term i: 247, qualified;
circulating movement 1 sequence obtained: 232, respectively, and the former term i: 257; qualified;
cyclic shift sequences obtained 2: 322, respectively, and the former term i: 357; qualified;

Sample 2 [O]
genes.in
. 5
. 3 -1 2 -3. 4
genes.out
2

[Data] range
for data of 30%, satisfies 1 <= N <= 5,000
for the 50% data satisfies 1 <= N <= 10,000
to 100% of the data satisfies 1 <= N <= 1,000,000, -1,000 < = Ai <= 1,000



The prefix and push out a formula to push on the line. Scan maintain a minimum.

Greater than or equal to 0 as the start greater than a 0.

#include<bits/stdc++.h>
#define co const
template<class T>T read(){
    T data=0,w=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-') w=-w;
    for(;isdigit(ch);ch=getchar()) data=data*10+ch-'0';
    return data*w;
}
template<class T>T read(T&x){
    return x=read<T>();
}
typedef long long ll;
using namespace std;

co int N=1e6+1;
int n,s[N];
bool v[N];
int main(){
    freopen("genes.in","r",stdin),freopen("genes.out","w",stdout);
    read(n);
    for(int i=1;i<=n;++i) s[i]=s[i-1]+read<int>();
    for(int i=n-1,mv=s[n];i>=0;mv=min(mv,s[i]),--i)
        v[i]=mv>=s[i];
    int ans=v[0];
    for(int i=1,mv=s[1];i<=n-1;++i,mv=min(mv,s[i]))
        ans+=v[i]&(mv+s[n]-s[i]>=0);
    printf("%d\n",ans);
    return 0;
}

Question three: the shortest path

[Problems] Description
is given of n points in a plane, referred to the abscissa of the minimum point A, the maximum point is B, Zxd now want to know elapsed time (A point twice) to go from point A at each to B, the shortest path back to a's. But he was an obsessive, he has a lot of weird requirements and restrictions:

  1. A come from the time B, only small dots come from the abscissa of large dots.
  2. When the B back to A, can only come from the large horizontal axis of little dots.
  3. There are two specific points b1 and b2, b1 at 0 to n-1 of the road, b2 n-1 to 0 in the road.
    You help him solve this problem to help him treat it!

[Input format
of the first row of three integers n, b1, b2, (0 <b1, b2 <n-1 , and b1 <> b2). n represents the number of points, from 0 to n-1 numbers, b1 and b2 are two special point number.
The following n lines of two integers x, y represent the coordinates of the point (0 <= x, y < = 2000), gives the order from 0 point. Doctor Gao point in order to facilitate his treatment, has been given by x in increasing order lined up.

[] Output format
only one line, the output of path length (accurate to two after the decimal point).

[Sample input]
. 5. 3. 1
. 1. 3
. 3. 4
. 4. 1
. 7. 5
. 8. 3

[Sample output]
18.18

[Explain] Sample
Shortest Path: 0-> 1-> 4-> 3-> 2-> 0

[Data] range
of 20% of the data n-<= 20 is
60% of the data n-<300 =
100% of the data n <= 1000
for all the data x, y, b1, b2 as described in the title.



The road back to the time to go as the two roads, then became a question above purple book.

Since this problem has b1, b2 constraints, the state can not be halved. f [i, j] represents the minimum value in the case where two endpoints, and to ensure that less points max (i, j) are gone through. Transfer to transfer only +1 max (i, j).

DP is more skilled.

#include<bits/stdc++.h>
#define co const
template<class T>T read(){
    T data=0,w=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-') w=-w;
    for(;isdigit(ch);ch=getchar()) data=data*10+ch-'0';
    return data*w;
}
template<class T>T read(T&x){
    return x=read<T>();
}
typedef long long ll;
using namespace std;

co int N=1e3;
int n,b1,b2;
#define x first
#define y second
pair<int,int> p[N];
double dis(int a,int b){
    return sqrt(pow(p[a].x-p[b].x,2)+pow(p[a].y-p[b].y,2));
}
double f[N][N];
int main(){
    freopen("paths.in","r",stdin),freopen("paths.out","w",stdout);
    read(n),read(b1),read(b2);
    for(int i=0;i<n;++i) read(p[i].x),read(p[i].y);
    for(int i=0;i<n;++i) fill(f[i],f[i]+n,1e18);
    f[0][0]=0;
    for(int i=0;i<n-1;++i)for(int j=0;j<n-1;++j)if(f[i][j]<1e18){
        int t=max(i,j)+1;
        if(t!=b2) f[t][j]=min(f[t][j],f[i][j]+dis(i,t));
        if(t!=b1) f[i][t]=min(f[i][t],f[i][j]+dis(j,t));
    }
    double ans=1e18;
    for(int i=0;i<n-1;++i){
        ans=min(ans,f[n-1][i]+dis(i,n-1));
        ans=min(ans,f[i][n-1]+dis(i,n-1));
    }
    printf("%.2lf\n",ans);
    return 0;
}

165->290

Guess you like

Origin www.cnblogs.com/autoint/p/11002021.html