Mock race 10-14 Exam again rollover

Source: Internet
Author: User
Tags rounds

10-14 Exams

7 O'Clock start the exam, the first problem, ah, directly take the mold in the process of adding the business can be, cut off cut off.

1. Light Sword
(Sword.pas/c/cpp)
"Title description"
Xiao Lin and Liang each have a lightsaber, the length of a and B, respectively, they take the lightsaber to a contest. Every
Round, the long lightsaber will chop to the short lightsaber, after the cut, the short light sword intact, and the long lightsaber is cut into two paragraphs,
The length of the cut is exactly equal to the length of the short lightsaber. If the two lightsaber lengths are equal, the contest ends. Excuse me
How many rounds will Xiao Lin and Liang have to contest?
"Input Format"
The first line is an integer T that represents the number of data groups.
The next T line is two positive integers A/b, which indicates the initial state of the lightsaber length.
"Output Format"
Each set of data outputs an integer that indicates the ability to perform several rounds of the contest.
"Sample Input"
3
1 8
3 7
6 6
"Sample Output"
7
4
0
"Data Size"
For 40% data, 0 < b <=, 1 <= T <= 20;
For 100% of data, 0 < b <= 10^18,1 <= T <= 1000.

Code

#include<iostream>#include<cstdio>#define int long longusing namespace std;inline int read(){    int sum=0,f=1;char ch=getchar();    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while(ch>='0'&&ch<='9'){sum=(sum<<1)+(sum<<3)+ch-'0';ch=getchar();}    return sum*f;}int t,a,b,ans;long long work(long long x, long long y){    if(x<y)swap(x, y);    if(y==1)return x-1;    if(x==y)return 0;    if(y==0)return -1;    else return work(y,x%y)+x/y;}signed main(){    freopen("sword.in","r",stdin);    freopen("sword.out","w",stdout);    t=read();    for (int i=1;i<=t;i++){        long long x, y;        x=read();y=read();        printf("%lld\n",work(x, y));    }    fclose(stdin);    fclose(stdout);    return 0;}

7 Point 25 start to look at T2, the first feeling is very disgusting ah, first of all, regardless of a \ (n^5\) of the search again.

After the storm search immediately think of yesterday Zager out of the T2,\ ( meet in the middle\) Ah, first search the first three layers, then search the two layers, and then lower_bound to find the opposite number on the line, this is over.

2, 0
(Zero.pas/c/cpp)
"Title description"
The Kobayashi has 2 collections, which have 3 collections, and the five collections are of equal size, and the packages in the collection
it contains integers. Now the two of them are going to have a mental arithmetic match. The rule of the game is to put these five sets
Together, who can choose a number from each set so that the sum of the five numbers chosen is 0, and who will receive
To win. Since these five collections are not small, and the small forest and bright light in advance do not know whether this can exist
Five numbers, so they decide to hand over five sets to you, and you will be programmed to determine if there is a compliance bar
Five numbers for each piece.
"Input Format"
The first line, an integer N, represents the size of the collection.
The next five lines each row N integers, representing the elements within these five sets.
"Output Format"
If you can find five numbers that match the criteria, output "YES" or Output "NO".
"Sample Input"
3
1-2 9
-1 2 1
-3 5 1
-1 7 6
-4-1-7
"Sample Output"
YES
"Data Size"
For 30% data, 1 <= N <= 20;
For 50% data, 1 <= N <= 100;
For 100% of data, 1 <= N <= 200,-10^8 <= a[i] <= 10^8,a[i] are elements in the collection

Code

#include <iostream> #include <cstdio> #include <algorithm> #define INT long longusing namespace std;    const int Wx=8000017;inline int read () {int Sum=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {sum= (sum<<1) + (sum<<3) +ch-' 0 '; Ch=getchar ();} return sum*f;}        int A[wx],b[wx];int s[70][4170];int cnt,tot,num,n;void dfs (int step,int num) {if (step>=4) {a[++cnt]=num;    Return    } for (int i=1;i<=n;i++) {DFS (step+1,num+s[step][i]);        }}void DFS (int step,int num) {if (step>=3) {b[++tot]=num;    Return    } for (int i=1;i<=n;i++) {DFS (step+1,num+s[step+3][i]);    }}signed Main () {freopen ("zero.in", "R", stdin);    Freopen ("Zero.out", "w", stdout);    N=read ();        for (int i=1;i<=5;i++) {for (int j=1;j<=n;j++) {s[i][j]=read ();    }} dfs (1,0);    DFS (1,0);    Sort (a+1,a+1+cnt); for (int i=1;i<=tot;i++) {int tmp=lower_bound (A+1,a+1+cnt,-b[i])-A;            if (a[tmp]==-b[i]&&tmp<=cnt&&tmp>=1) {printf ("yes\n");        return 0;    }} printf ("no\n");    Fclose (stdin);    Fclose (stdout); return 0;}

Eight o'clock Liver T3, looks very difficult ah, ghost 2048, not.

But it must be DP Ah, the blind chicken set the state, but the complexity of the feeling is not quite right ah, the binary split up and slipped away.

3, 2048
(2048.pas/c/cpp)
"Title description"
Kobayashi and Liang are reviewing the 2048 game recently. As their game level is superb, they feel
No challenge, so I decided to design a similar game.
In the game they designed, the numbers are lined up in a linear sequence, and each time the player can
Meaning two identical number a merges, becomes a new number 2*a, when merges 2048 when the game obtains wins
Philip After the design, they found the game more simple than the original version, so they began to count
Calculate, for a given sequence of length n, it has a total of how many sub-sequences can be combined 2048. Please
Give the value of this modulus 998244353.
"Input Format"
The first line has an integer n.
The second row n integer Ai, which represents the number in the sequence.
"Output Format"
An integer that is the answer you are seeking.
"Sample Input"
2
2048 2048
"Sample Output"
3
"Data Size"
For 40% of data, n <= 20;
For 70% of data, n <= 500;
For 100% of data, 1 <= n <= 100000,1 <= Ai <= 2048.

Code

#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #define INT Long longusing namespace Std;const int wx=100017;const int mod=998244353;int n,cnt;int a[20],flag[wx],wx[20];int a1[wx],a2[    Wx],a3[wx];int f[20][wx];inline int Read () {int Sum=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {sum= (sum<<1) + (sum<<3) +ch-' 0 '; Ch=getchar ();} return sum*f;}    int ksm (int a,int b) {int re=1;        while (b) {if (b&1) Re=re*a%mod;        A=a*a%mod;    b>>=1; } return re;}    void Pre () {memset (flag,-1,sizeof (flag));        for (int i=0;i<=11;i++) {flag[1<<i]=i;    wx[i]=2048/(1<<i);    } a1[0]=1;    for (int i=1;i<wx;i++) A1[i]=a1[i-1]*2%mod;    A3[0]=a2[0]=1;        for (int i=1;i<wx;i++) {a3[i]=a3[i-1]*i%mod;    A2[I]=KSM (a3[i],mod-2);    }}void Jia (int &a,int b) {a+=b; if (A>=mod) a-=mod;} Signed Main () {freopen ("2048.in", "R", stdin);    Freopen ("2048.out", "w", stdout);    N=read ();p re ();        for (int i=0;i<n;i++) {int x;x=read ();        if (flag[x]==-1) cnt++;    else a[flag[x]]++;    } memset (f,0,sizeof f);    int num=min (a[0],wx[0]);    int sum=0,val;        for (int i=0;i<=num;i++) {val=a3[a[0]]*a2[i]%mod*a2[a[0]-i]%mod;        F[0][i]=val;    Jia (Sum,val);    } if (Wx[0]<a[0]) f[0][wx[0]]= (f[0][wx[0]]+a1[a[0]]-sum+mod)%mod;        for (int i=1;i<=11;i++) {num=min (a[i],wx[i]);        sum=0;            for (int j=0;j<=num;j++) {val=a3[a[i]]*a2[j]%mod*a2[a[i]-j]%mod;            Jia (Sum,val);                    for (int k=0;k<=wx[i-1];k++) if (F[i-1][k]) {int temp=min (j+k/2,wx[i]);                Jia (F[i][temp],val*f[i-1][k]%mod);            }} if (A[i]>wx[i]) {val= (a1[a[i]]-sum+mod)%mod;    for (int j=0;j<=wx[i-1];j++) if (F[i-1][j])                Jia (F[i][wx[i]],f[i-1][j]*val%mod);    }} printf ("%lld\n", f[11][1]*a1[cnt]%mod); return 0;}

PostScript Summary:
This test was originally AK, but for a variety of reasons only test 160 points, uncomfortable ...

The second problem in the debug when the \ (8*10^6\) changed to the \ (1*10^6\), after four points all re, is enough silly force.

The third question did not write Cstdio, direct Bauku, this lovely dev, really good.

First of all, I did a good job, but the details are in addition to the fatal problem, so as they say, the heart sank down, continue to refuel it.

Mock race 10-14 Exam again rollover

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.