多校+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\n",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

422 2

Output

2

Input

533 4 3

Output

3

Input

311231 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\n",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\n",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\n",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\n");
        else
            printf("Bob\n");
    }

    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("\n");
76         else
77             printf("Just a legend\n");
78         memset(s2,0,sizeof(s2));
79         memset(book,0,sizeof(book));
80     }
81
82     return 0;
83 }
时间: 2024-10-11 10:23:12

多校+CF简单题的相关文章

CF简单题选做

And Reachability 给定一个长度为 \(n\) 的序列 \(a\) ,定义 \((x,y)\) "可到达" 为:可以选出若干个位置 \(p_1...p_k\) ,使得 \(\forall x\le p_i \le y\) \(\forall a_{p_i}\&a_{p_{i+1}}\not=0\) , \(q\) 次询问 \((x,y)\) 是不是 "可到达" 的 \(n,q,a_i\le 3\times 10^5\) tags : dp ,

hdu 4970 Killing Monsters(简单题) 2014多校训练第9场

Killing Monsters                                                                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Kingdom Rush is a popular TD game, in which you should b

北方多校 又是一道简单题

又是一道简单题 12000ms 65536K 给出一棵有根树,每次查询给出两个节点 u 和 v,假设节点 f 是u,v的最近公共祖先,请查询以 f 为根的子树中,不在 u 到 v 这条链上且标号最小的节点. 输入格式 第一行输入正整数 T(T <= 30),表示共有T组输入数据. 对于每组数据,第一行输入两个正整数 n,m(n <= 50000,m <= 50000),表示节点数和询问数,节点编号 1 到 n,其中 1 是根节点. 接下来 n - 1 行,每行输入两个正整数u,v,表示标

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来...每道题都错好多次...很考察细节.比如这道....WA了无数次.... 这题的思路自己真心想不到...这题是将进制后的数分别是1位,2位,3位和更多位的分开来计算. 当是1位的时候,显然只有3到6,此时只能是-1 当是2位的时候,可以转换成一元一次方程求解 当是3位的时候,可以转换成一元二次方程求解 当是4位的时候,此时最多也只有7000个数,7000^3接近1e12.所以剩下的直接枚举进制数来判断即可. 代码如下: #include <i

poj2105 IP Address(简单题)

题目链接:http://poj.org/problem?id=2105 Description Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format. A dotted decima

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&

数论 --- 简单题

吃糖果 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 22376    Accepted Submission(s): 6396 Problem Description HOHO, 终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一 种,这样:

CSU 1425 NUDT校赛 I题 Prime Summation

这个题本来有希望在比赛里面出了的 当时也想着用递推 因为后面的数明显是由前面的推过来的 但是在计算的时候 因为判重的问题 ...很无语.我打算用一个tot[i]来存i的总种树,tot[i]+=tot[j]//j为可以由j推到i的一系列数,但这样是不对的,会产生大量重复计算... 看了下标程才发现要用二维来计算出种类总数,f[i][j]+=sum(f[i-j][k]) 表示在推i数的时候,第一个素数为j的种类数,注意j一定为素数,而且k不能大于j...标程里面处理的比较简练,就学了下他的写法. 至

BZOJ 2683 简单题 ——CDQ分治

简单题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) for (int i=j;i<=k;++i) #define D(i,j,k) for (int i=j;i>=k;--i) #define maxn 2000005 int sum[maxn]; void a