201,500-degree Star Qualifying tournament

Source: Internet
Author: User
Tags cas min printf first row time limit cmath

Big Move accepts:1516 submissions:6288 time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others) Problem D Escription

Recently, b factory organized a big move, everyone to follow the instructions to change to the designated seat. The indicated content is that the person sitting on position I is moving to position J. Now there are n people in plant B, one to n positions. After the move is also one by one corresponding, change only the rank.

After the first move, the degree of bear due to negligence, but also asked you to follow the original instructions for a move. So, the wit of it thought: again according to the instructions to move home once again can restore the first time the appearance of the move. As a result, plant B has carried out an unprecedented three consecutive moves.

While we all know that the "wit" of a bear is often worrying, it is inconceivable that this is a real thing. The result of the third move is exactly the same as the result of the first time.

So, how many kinds of instructions are going to make this happen? If at least one of the two instructions has a different target location, the two instructions are considered to be not the same. Input

The first line is an integer t, which represents the T group data.

Each set of data contains an integer N (1≤n≤1000000). Output

For each set of data, output one line of case #i: Then output the result, modulo 1000000007. Sample Input

2
1
3
Sample Output
Case #1:
1 case
#2:
4
Idea: Dp[i] represents I, two times move back to the original position of the method, then the state transfer equation can be obtained

dp[i]=dp[i-1]+dp[i-2]* (n-1)

Indicates that the newly added person should either move to himself or choose a person from the front to form a two-tuple

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define LL Long Long
const int  N = 1000005;
Const LL mod = 1000000007;

LL Dp[n];
void init ()
{
    dp[1]=1;
    dp[2]=2;
    for (int i=3; i<n; i++)
    {
        dp[i]=dp[i-1]+ (i-1) *dp[i-2];
        Dp[i]%=mod;
    }

}
int main ()
{
    int t,n;
    scanf ("%d", &t);
    int test=1;
    Init ();
    while (t--)
    {
        printf ("Case #%d:\n", test++);
        scanf ("%d", &n);
        printf ("%d\n", Dp[n]);
    }
    return 0;
}

Chessaccepts:345 submissions:2382 time limit:6000/3000 MS (java/others) Memory limit:65536/65536 K (java/others) Problem De Scription

There was an injured king on the N∗m's chessboard and a knight who was going to rescue the king, and they had to move each unit time to find each other. As shown in the figure below, the black legend indicates where the King (right) or knight (left) is currently located, and the gray position indicates where they might have been in a single move. The king was seriously injured, so he had to get the knight's help in the K unit time, or he would hang up. Asked whether the king can be in the K unit time to obtain assistance, if possible, the shortest amount of time required to spend units.

Input

The first line contains an integer t, (1≤T≤50) represents the number of groups of test data, and the next T group tests the data.

The first row of each set of test data contains three integer n,m,k, and 2≤n,m≤1000, 1≤k≤200. The second line is two integers xking,yking, corresponding to the coordinates of the king's Square. The third line is two integers xknight,yknight, corresponding to the coordinates of the knight's Square. One of the 1≤xking,xknight≤n,1≤yking,yknight≤m is to ensure that the knight and the King are not in the same box at first and they can move. : Output

For each set of test data, output two lines:

The first line of output: "Case #i:". I represents the test data for group I.

The second line outputs the results of the test data, and if the king can be rescued, the output will take as many units of time as the fastest. Otherwise, the output is "oh,no!". Sample Input

2
3 2 1
1 1
3 1
3 3 1
1 1
Sample Output
Case #1:
1 case
#2:
oh,no!

Idea: first BFS processing Office king and knight to each node in the shortest time, if King arrives first, then answer time is Knight arrive time (because if King arrives at this node at k time, then certainly can arrive at this node in >=k time), If Knight arrives first, then time is the time when King arrives + if the parity is different, add an extra 1, because to move at the same time, you must have the same parity to reach this point

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector > #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #
Include<algorithm> using namespace std;
const int maxn=1010;
const int inf=0x3f3f3f3f;
int DIS[2][MAXN][MAXN];
int n,m,k;
int x[2],y[2];
int dx[2][8]={{-1,-1,-1,0,1,1,1,0},{-1,-2,-2,-1,1,2,2,1}};
int dy[2][8]={{-1,0,1,1,1,0,-1,-1},{-2,-1,1,2,2,1,-1,-2}};
struct node {int x,y,t;};
    int main () {int t,cas=1;
    scanf ("%d", &t);
        while (t--) {scanf ("%d%d%d", &n,&m,&k);
        scanf ("%d%d%d%d", &x[0],&y[0],&x[1],&y[1]);
        Queue<node> Q;
        memset (dis,inf,sizeof (dis)); for (int s=0; s<2;
            s++) {while (!q.empty ()) Q.pop ();
            dis[s][x[s]][y[s]]=0;
            Node A;
            a.x=x[s],a.y=y[s],a.t=0;
            Q.push (a);
    while (!q.empty ())        {node B=q.front (); Q.pop ();
                if (b.t>k) break;
                    for (int i=0;i<8;i++) {a.x=b.x+dx[s][i],a.y=b.y+dy[s][i]; if (a.x<=0| | a.x>n| | a.y<=0| | a.y>m| |
                    Dis[s][a.x][a.y]<inf) continue;
                    a.t=b.t+1;
                    DIS[S][A.X][A.Y]=A.T;
                Q.push (a);
        }}} int ans=inf+10; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {if (dis[1][i][j]<=dis[0][i][
                J]) Ans=min (ans,dis[0][i][j]+ (dis[0][i][j]&1^dis[1][i][j]&1));
            else if (dis[1][i][j]>1) ans=min (Ans,dis[1][i][j]);
        } printf ("Case #%d:\n", cas++);
        if (ans<=k) printf ("%d\n", ans);

    else printf ("oh,no!\n");
} return 0; }

monotone intervalaccepts:358 submissions:938 time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others) Problem Des Cription

The Hundred-degree recent blog, and then found an interesting question.

As shown in the figure below, it is a 12-digit number 014326951987, its number is gradually larger, then smaller, then larger, then smaller, and become larger, and eventually become smaller. We would say that the total includes

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.