2021.3.21-2021年度训练联盟热身训练赛第三场

B.

https://ac.nowcoder.com/acm/contest/13168/B

题目内容:

链接:https://ac.nowcoder.com/acm/contest/13168/B
来源:牛客网


Quido and Hugo are making a chocolate cake. The central ingredient of the cake is a large chocolate bar, lying unwrapped on the kitchen table. The bar is an M \times NM×N rectangular grid of chocolate blocks. All of the MNMN blocks are rectangles of identical shape and size. The chocolate bar is of top quality and the friends want to eat part of it, before the rest is used in the cake.

"OK," says Quido, "let's divide the whole bar into two triangular chunks by a straight diagonal cut from its upper-left corner to its lower-right corner. We will then eat all of the blocks which have been cut exactly in half, into two equal-area pieces. You will eat one half and I will eat the other half of each such block. All other blocks, that is, the blocks which are either uncut or cut into two parts of different sizes, will go directly into the cake. Of course, we will make sure the cut is perfectly precise.

Let's see how much chocolate we get to eat!"

输入描述:
The input consists of two space-separated integers MM and NN given on a single line, (where 1 ≤ M, N ≤ 10^{18}1≤M,N≤10 
18
 ). The numbers MM and NN denote the number of blocks in one column and in one row, respectively, in the chocolate bar.
输出描述:
Print the number of blocks of the chocolate bar which are cut into exactly two pieces of equal area.
示例1
输入
复制
6 10
输出
复制
2
示例2
输入
复制
75206452536745713 10322579177493903
输出
复制
40318322589
View Code

题解:一个m*n的巧克力条,由m*n块形状和大小的小巧克力块组成,从左上角到右下角切开,求有多少块小巧克力被切成了等面积的两小块

思路:     1  *  3的巧克力条

 

 中心在黑点处,此时红色区域与橙色区域面积相等,此时就可以吃一个

1   *  4  :

 此时中心在线上,可以吃到的巧克力数为 0

2  *  4:

 此时可以吃到的巧克力数为 0

2 *  6:

 可以看成两个1*3的情况,所以就可以吃到2块

找规律:求他们的公因数,再看比值

我们可以求出 t=__gcd(m,n), 再看m/t 与n/t 中有无偶数,如果有则结果为0 ,反之结果为 t;

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll m,n;
    scanf("%lld %lld",&m,&n);
    ll t=__gcd(m,n);
    if((m/t)%2==0||(n/t)%2==0)cout<<0<<endl;
    else cout<<t<<endl;

}

K. Summer Trip

题目内容:

链接:https://ac.nowcoder.com/acm/contest/13168/K
来源:牛客网

Leo has started a job in a travel agency. His first task is to organize a summer trip to an exotic overseas city. During the summer season, events of various types take place in the city: sports matches, concerts, beach parties, and many others. At any given time, there is exactly one event taking place. Events of any particular type may take place more than once during the season. The itinerary of events that Leo offers to his clients cannot be chosen arbitrarily; the company requires them to form a so-called "good itinerary." A good itinerary is a consecutive sequence of at least two events in the summer season, where the first and last events are of different types, and they are both unique among all event types during the sequence. For example, if the first event in a good itinerary is a beach party, none of the other events during the itinerary can also be a beach party. There are no other restrictions on the event types in the sequence of a good itinerary.

Before he starts organizing the trip, Leo wants to know the total number of good itineraries that are possible given a calendar of events that will take place over the summer season.

输入描述:


The input consists of one line with a string describing the sequence of event types in the summer season. All characters are lowercase English letters (a - z)(a−z), with different letters represent different types of events. Character ii of the string encodes the ii-th event of the summer. There are no blanks or spaces in the string.

The length of the input string is at least 22 and at most 100 000100000 characters.



输出描述:
Print the number of good itineraries that exist for the given summer season.
示例1
输入
复制
abbcccddddeeeee
输出
复制
10
示例2
输入
复制
thenumberofgoodstringsis
输出
复制
143
View Code

题意:给出一个字符串,求至少连续的两个字符组成的不同的子字符串的数量,要求:第一个字符和最后一个字符在子字符串中只能出现一次,其他随意多少个都可,求有多少中

思路:用一个数组记录首个字母,用另一个数组记录之后的字母,用于判断他们的出现情况,

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    int m,a[100],b[100];//分别用于记录首个字母,以及之后加入的字母
    int ct=0;
    cin>>s;
    m=s.size();
    for(int i=0;i<m;i++)
    {
        memset(a,0,sizeof(a));//遍历完一个后清零
        memset(b,0,sizeof(b));
        a[s[i]-'a']=1;  //标记下首字母
        for(int j=i+1;j<m;j++)
        {
            if(a[s[j]-'a']!=0)break;//如果新加入的字母与首字母一样就退出循环
            if(b[s[j]-'a']!=0)//如果后来加入的字母已出现过,就把它记为下一个首字母,现在就不加入次数中
/*
如:abbccdde
a a[s[0]-'a']=1;
ab b[s[1]-'a']=1; ct=1
abb continue; 下一次会 i+1 到 第二个b作为首字母再次遍历
abbc b[c-'a']=1; ct=2 ...
*/
continue; ct++; b[s[j]-'a']=1;//标记新加入的字母 } } cout<<ct<<endl; }

 

posted @ 2021-03-25 22:10  西瓜0  阅读(93)  评论(0)    收藏  举报