zoukankan      html  css  js  c++  java
  • 多校+CF简单题

    A - The Unsolvable Problem
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number. 
    Given an integer n(2 <= n <= 10 9).We should find a pair of positive integer a, b so that a + b = n and [a, b] is as large as possible. [a, b] denote the least common multiplier of a, b.
     

    Input

    The first line contains integer T(1<= T<= 10000),denote the number of the test cases. 
    For each test cases,the first line contains an integer n.
     

    Output

    For each test cases, print the maximum [a,b] in a line.
     

    Sample Input

    3 2 3 4
     
     
     
    题目大意:
      就是说,给你一个数字n,n的范围在10^9之间,使得n=a+b的时候,求出最大的 lcm(a,b)
    解题思路:
      一开始直接暴力,果断T了,10^9/2 = 5*10^8,。。。。。
      正解就是分n是奇数还是偶数考虑,如果是n是奇数的话,一定能够分成a=n/2,b=(n-n/2)的形式,这样一来,我们就得到了a和b的最小公倍数一定是a*b,因为a和b一个是奇数一个是偶数,那么gcd(a,b)=1,则 lcm(a,b) = a*b.
      然后,当n是偶数的时候,还有两种情况,就是n/2,自然想到lcm(a,b) = a*b/gcd(a,b),当然是使得a*b尽可能的大,而gcd(a,b)尽可能的小了,所以,如果n是偶数的话,我们上来后从n/2开始枚举直到找到两个数字的最大公余数是1就停下来,然后结果就是i*(n-i).
    代码:
     1 # include<cstdio>
     2 # include<iostream>
     3 
     4 using namespace std;
     5 
     6 
     7 int gcd ( int a,int b )
     8 {
     9     if ( b==0 )
    10         return a;
    11     return gcd(b,a%b);
    12 }
    13 
    14 
    15 int main(void)
    16 {
    17     int t;scanf("%d",&t);
    18     while ( t-- )
    19     {
    20         long long ans = 0;
    21         long long n;scanf("%lld",&n);
    22 
    23 
    24         if ( n%2 )
    25             ans = (n/2)*(n-n/2);
    26         else
    27         {
    28             for ( long long i = n/2;i>=1;i-- )
    29             {
    30                 if ( gcd(i,n-i)==1 )
    31                 {
    32                     ans = i*(n-i);
    33                     break;
    34                 }
    35             }
    36         }
    37         printf("%lld
    ",ans);
    38 
    39     }
    40 
    41 
    42     return 0;
    43 }
    B - Vasya's Calendar
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.

    The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.

    Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.

    A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.

    Input

    The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).

    The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).

    The third line contains n space-separated integers: ai(1 ≤ ai ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.

    Output

    Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.

    Sample Input

    Input
    4
    2
    2 2
    Output
    2
    Input
    5
    3
    3 4 3
    Output
    3
    Input
    31
    12
    31 28 31 30 31 30 31 31 30 31 30 31
    Output
    7

    Hint

    In the first sample the situation is like this:

    • Day 1. Month 1. The clock shows 1. Vasya changes nothing.
    • Day 2. Month 1. The clock shows 2. Vasya changes nothing.
    • Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1.
    • Day 2. Month 2. The clock shows 2. Vasya changes nothing.
    In total, Vasya manually changed the day number by 1 exactly 2 times.
    题目大意:
      就是说,给你一个长度为n的序列,然后每个数字的结果都不能超过d,每次从第i个数字向第i+1个数字转换的时候,就会出现手动+1,超过d后,就要手动置1,问最后的使得手动次数使得满足要求
    解题思路:
      直接扫一遍就行,关键是把题目读懂,,,
    代码:
     1 # include<cstdio>
     2 # include<iostream>
     3 
     4 using namespace std;
     5 
     6 # define MAX 2333
     7 
     8 int a[MAX];
     9 
    10 int main(void)
    11 {
    12     int ans = 0;
    13     int n,d;scanf("%d%d",&d,&n);
    14     for ( int i = 0;i < n;i++ )
    15         scanf("%d",&a[i]);
    16     for ( int i = 0;i < n-1;i++ )
    17         ans+=(d-a[i]);
    18 
    19     printf("%d
    ",ans);
    20 
    21     return 0;
    22 }
    C - Counting Rhombi
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties:

    • Have positive area.
    • With vertices at integer points.
    • All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h),(0, h). In other words, for all vertices (xi, yi) of the rhombus the following conditions should fulfill: 0 ≤ xi ≤ w and 0 ≤ yi ≤ h.
    • Its diagonals are parallel to the axis.

    Count the number of such rhombi.

    Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.

    Input

    The first line contains two integers w and h(1 ≤ w, h ≤ 4000) — the rectangle's sizes.

    Output

    Print a single number — the number of sought rhombi.

    Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

    Sample Input

    Input
    2 2
    Output
    1
    Input
    1 2
    Output
    0

    Hint

    In the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1).

    题目大意:

       就是说在一个w*h的网格中,找出由几个点能够组成对角线平行于x轴和y轴而且四条边相等的菱形。

    解题思路:

      直接枚举菱形的中点个数就OK了,慢慢画下,5个图一般就出规律了。。。

    代码:

     1 # include<cstdio>
     2 # include<iostream>
     3 
     4 using namespace std;
     5 
     6 
     7 int main(void)
     8 {
     9     int w,h;scanf("%d%d",&w,&h);
    10     long long sum = 0;
    11     for ( int i = 1;i <= w;i++ )
    12     {
    13         for ( int j = 1;j <= h;j++ )
    14         {
    15             sum+=min(i,w-i)*min(j,h-j);
    16         }
    17     }
    18 
    19     printf("%lld
    ",sum);
    20 
    21     return 0;
    22 }
    E - Hehe
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    As we all know, Fat Brother likes MeiZi every much, he always find some topic to talk with her. But as Fat Brother is so low profile that no one knows he is a rich-two-generation expect the author, MeiZi always rejects him by typing “hehe” (wqnmlgb). You have to believe that there is still some idealized person just like Fat Brother. They think that the meaning of “hehe” is just “hehe”, such like “hihi”, “haha” and so on. But indeed sometimes “hehe” may really means “hehe”. Now you are given a sentence, every “hehe” in this sentence can replace by “wqnmlgb” or just “hehe”, please calculate that how many different meaning of this sentence may be. Note that “wqnmlgb” means “我去年买了个表” in Chinese.
     

    Input

    The first line contains only one integer T, which is the number of test cases.Each test case contains a string means the given sentence. Note that the given sentence just consists of lowercase letters. 
    T<=100 
    The length of each sentence <= 10086
     

    Output

    For each test case, output the case number first, and then output the number of the different meaning of this sentence may be. Since this number may be quite large, you should output the answer modulo 10007.
     

    Sample Input

    4 wanshangniyoukongme womenyiqichuqukanxingxingba bulehehewohaiyoushi eheheheh
     

    Sample Output

    Case 1: 1 Case 2: 1 Case 3: 2 Case 4: 3
     

    题目大意:

      这题目有点意思,就是说,我现在有一个字符串,然后让你求出有多有个hehe,每个hehe可以被替换成为wqnmlgb,找规律的题目,直接上来打表然后运用乘法原理就好了。

    解题思路:

      fac[i] = fac[i-1]+fac[i-2],  然后 ans = ( ans*fac[cnt])%MOD;

    代码:

     1 # include<cstdio>
     2 # include<iostream>
     3 # include<cstring>
     4 
     5 using namespace std;
     6 
     7 # define MAX 2333
     8 # define MOD 10007
     9 
    10 char s[MAX];
    11 int fac[10088];
    12 
    13 
    14 void init()
    15 {
    16     fac[0] = 1;
    17     fac[1] = 1;
    18     fac[2] = 2;
    19     for ( int i = 3;i <= 10086;i++ )
    20     {
    21         fac[i] = (fac[i-1]+fac[i-2])%MOD;
    22     }
    23 }
    24 
    25 int main(void)
    26 {
    27     init();
    28     int icase = 1;
    29     int t;scanf("%d",&t);
    30     while ( t-- )
    31     {
    32         int cnt = 0, ans = 1;
    33         scanf("%s",s);
    34         int len = strlen(s);
    35         for ( int i = 0;i < len; )
    36         {
    37             if ( s[i]=='h'&&s[i+1]=='e' )
    38             {
    39                 cnt++;
    40                 i+=2;
    41             }
    42             else
    43             {
    44                 ans = (ans*fac[cnt])%MOD;
    45                 cnt = 0;
    46                 i++;
    47             }
    48 
    49         }
    50         ans = (ans*fac[cnt])%MOD;
    51 
    52         printf("Case %d: %d
    ",icase++,ans);
    53     }
    54 
    55 
    56     return 0;
    57 }
    F - Fliping game
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Alice and Bob are playing a kind of special game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with one in each grid and every coin may be upward or downward freely. Then they take turns to choose a rectangle (x 1, y 1)-(n, m) (1 ≤ x 1≤n, 1≤y 1≤m) and flips all the coins (upward to downward, downward to upward) in it (i.e. flip all positions (x, y) where x1≤x≤n, y 1≤y≤m)). The only restriction is that the top-left corner (i.e. (x 1, y 1)) must be changing from upward to downward. The game ends when all coins are downward, and the one who cannot play in his (her) turns loses the game. Here's the problem: Who will win the game if both use the best strategy? You can assume that Alice always goes first.
     

    Input

    The first line of the date is an integer T, which is the number of the text cases. 
    Then T cases follow, each case starts with two integers N and M indicate the size of the board. Then goes N line, each line with M integers shows the state of each coin, 1<=N,M<=100. 0 means that this coin is downward in the initial, 1 means that this coin is upward in the initial.
     

    Output

    For each case, output the winner’s name, either Alice or Bob.
     

    Sample Input

    2 2 2 1 1 1 1 3 3 0 0 0 0 0 0 0 0 0
     

    Sample Output

    Alice Bob
     
     

    题目大意:

      就是说, 有两个人,一个叫Alice,一个叫Bob,然后这两个人玩一个游戏,把一个n*m的只包含有0和1的棋盘上的棋子进行翻转。如果Alice将所有的棋子都被翻成了0的话,那么Alice就胜利了,反之,就是Bob胜利了。

    解题思路:

      看到后,感觉是什么nim游戏还是什么sg定理,,,(真是扯淡)这不就是最简单的博弈吗?就是说,只要最后一个棋子是0的话,那就绝壁是Alice胜利,如果最后一个棋子是1的话,那就绝壁是Bob胜利了。因为,想想啊, 如果最后一个棋子是1的话,那Alice不管怎么翻棋子,都会使最后一个棋子变成0,这样的话,Bob就输了,如果最后一个棋子是0的话,那么Alice的每次操作都会使他变成1,那么Bob就能胜利了,因为Bob可以把他变成0。

    代码:

    # include<cstdio>
    # include<iostream>
    
    using namespace std;
    
    int n,m;
    
    int main(void)
    {
        int t;scanf("%d",&t);
        while( t-- )
        {
            scanf("%d%d",&n,&m);
            int x;
            for( int i = 0;i < n;i++ )
                for( int j = 0;j < m;j++ )
                    scanf("%d",&x);
            if( x == 1 )
                printf("Alice
    ");
            else
                printf("Bob
    ");
        }
    
        return 0;
    }
    J - Password
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

    A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

    Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

    Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

    You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

    Input

    You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

    Output

    Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

    Sample Input

    Input
    fixprefixsuffix
    Output
    fix
    Input
    abcdabc
    Output
    Just a legend

    题目大意:

      就是说,给你一个字符串,让你找到一个子串,即是这个字符串的前缀,也是这个字符串的后缀,但是还在中间出现过,就是说,既不是前也不是后缀。

    解题思路:

      看上去很吓人,但是仔细一想还是很简单的,就是说,kmp中的next[]数组的巧妙运用了,如果next[]玩的好,这题就很水了,如果不会next[]数组,这题

    只能放了。我们知道next[i] = j 表示的是s(0,1,2,3,,,i-1)这个字符串的前缀后缀最大值,OK,有了这个概念的话,我们就把所有可能出现的长度记录下,然后我们

    贪心的从最后一位还是扫,如果book[next[i]]标记过,而且next[i]的数值不是0的话,我们就输出好了,如果next[i]的数值是0的话,我们就直接跳到i=next[i]的位置了。

    代码:

     1 # include<cstdio>
     2 # include<iostream>
     3 # include<cstring>
     4 
     5 using namespace std;
     6 
     7 # define MAX 1000004
     8 
     9 char s1[MAX],s2[MAX];
    10 int book[MAX];
    11 int next[MAX];
    12 
    13 
    14 void get_next ( int *next,char *s2,int lens )
    15 {
    16     int t1 = 0, t2;
    17     next[0] = t2 = -1;
    18     while ( t1 < lens )
    19     {
    20         if ( t2==-1||s2[t2]==s2[t1] )
    21         {
    22             t1++, t2++;
    23             next[t1] = t2;
    24         }
    25         else
    26             t2 = next[t2];
    27     }
    28 }
    29 
    30 
    31 int kmp ( int *next,char *s1,int lens1,char *s2,int lens2 )
    32 {
    33     int t1 = 0,t2 = 0;
    34     while ( t1 < lens1&&t2 < lens2 )
    35     {
    36         if ( t2==-1||s1[t1]==s2[t2] )
    37         {
    38             t1++; t2++;
    39         }
    40         else
    41             t2 = next[t2];
    42     }
    43     if ( t2==lens2 )
    44         return 1;
    45     else
    46         return 0;
    47 }
    48 
    49 
    50 int main(void)
    51 {
    52     while ( scanf("%s",s2)!=EOF )
    53     {
    54         int lens1 = strlen(s1), lens2 = strlen(s2);
    55         get_next( next,s2,lens2 );
    56        // int flag = kmp ( next,s1,lens1,s2,lens2 );
    57         for ( int i = 0;i < lens2;i++ )
    58             book[next[i]] = 1;
    59         int flag = 0, j = 0;
    60 
    61         for ( int i = lens2;next[i];i = next[i] )
    62         {
    63             if ( book[next[i]]==1 )
    64             {
    65                 for ( j = 0;j < next[i];j++ )
    66                 {
    67                     printf("%c",s2[j]);
    68                 }
    69                 flag = 1;
    70                 break;
    71             }
    72         }
    73 
    74         if ( flag )
    75             printf("
    ");
    76         else
    77             printf("Just a legend
    ");
    78         memset(s2,0,sizeof(s2));
    79         memset(book,0,sizeof(book));
    80     }
    81 
    82     return 0;
    83 }
     
  • 相关阅读:
    c++11:智能指针
    C++11:右值引用
    结构体与联合体
    数组与指针的区别?
    堆和栈的理论知识
    笔试点杂烩
    2、8、10、16进制输出
    单链表的反转
    签约新国都
    Linux下使用autoconf 和 automake 编译简单的HelloWorld
  • 原文地址:https://www.cnblogs.com/wikioibai/p/4538964.html
Copyright © 2011-2022 走看看