A. Links and Pearls

A necklace can be described as a string of links (’-’) and pearls (‘o’), with the last link or pearl connected to the first one.

You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can’t throw away any parts.

Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.

Note that the final necklace should remain as one circular part of the same length as the initial necklace.

Input
The only line of input contains a string s (3≤|s|≤100), representing the necklace, where a dash ‘-’ represents a link and the lowercase English letter ‘o’ represents a pearl.

Output
Print “YES” if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print “NO”.

You can print each letter in any case (upper or lower).

Examples
input
-o-o–
output
YES
input
-o—
output
YES
input
-o—o-
output
NO
input
ooo
output
YES

题意:
就是一串链环(“-”)和珍珠(“O”),使最后一个链环或珍珠连接到第一个链环,构成一串。 当然我们可以移除一个链环或一颗珍珠,并将其插入项链上其他两个现有链环或珍珠(或链环和珍珠之间)之间。这个过程可以重复任意多次,但不能丢弃任何部件。如果两颗珍珠之间没有其他珍珠,则认为它们是相邻的。
**问题是:**你能使每两颗相邻的珍珠之间的链节数相等吗?

解题:
直接构思一下:
1.珍珠大于链环时必然不相等;
2.当珍珠或者链环等于零时必然可以;
3.当珍珠为1,链环为任何数也必然可以
4.当珍珠不唯1 链环也不为1时,只要链环小与珍珠,以及链环可以被珍珠平分成多分相等的,也就是链环取余珍珠可以为零。
5.否则,都不成立。

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#define ll long long
using namespace std;
const int MM=1e6+5;
char s[MM];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int sum1=0,sum2=0;
    int s1,s2;
    for(int i=0; i<len; i++)
    {
        if(s[i]=='o')
        {
            sum1++;
        }
        else  if(s[i]=='-')
        {
            sum2++;
        }
    }
    //cout<<sum1<<" "<<sum2<<" "<<endl;
    if(sum1==0||sum2==0)
        printf("YES\n");
    else if(sum2!=1&&sum1==1)
        printf("YES\n");
    else if(sum1!=1&&sum2!=1&&sum1<=sum2)
    {
        s1=min(sum1,sum2);
        s2=max(sum1,sum2);
        if(s2%s1==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    else if(sum2>sum1)
    {
        printf("NO\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}

B. Marlin

The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4,n). The second village is located at (4,1) and its people love the Salmon pond at (1,n).

The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.

A person can move from one cell to another if those cells are not occupied by hotels and share a side.

Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

Input
The first line of input contain two integers, n and k (3≤n≤99, 0≤k≤2×(n−2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.

Output
Print “YES”, if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print “NO”.

If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is “#” if that cell has a hotel on it, or “.” if not.

Examples
input
7 2
output
YES

.#…
.#…

input
5 3
output
YES

.###.

题意:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
const int MM= 100;
int main() {
    int n, k;
    char w[5][MM];
    scanf("%d %d", &n, &k);
    printf("YES\n");//全部情况都成立
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < n+1; j++)
        {
            w[i][j] = '.';
        }
    }
    if (k % 2 == 0)//酒店为偶数时全部从左到右排2行与3行为酒店位置;
    {
        int p = 2;
        while (k > 0)
        {
            w[2][p] = '#';
            w[3][p] = '#';
            p++;
            k -= 2;
        }
    }
    else//否则 就先排第二行
    {
        if (k == 1)
        {
            w[2][n / 2 + 1] = '#';//最中间
        }
        else if (k == 3)
        {
            int s = (n + 1) / 2;
            w[2][s] = '#';
            w[2][s - 1] = '#';
            w[2][s + 1] = '#';
        }
        else
        {
            w[2][2] = '#';
            w[2][3] = '#';
            w[3][2] = '#';
            int p = 4;
            k -= 3;
            while (k > 0)
            {
                k -= 2;
                w[2][p] = '#';
                w[3][p] = '#';
                p++;
            }
        }
    }
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            printf("%c", w[i][j]);
        }
        printf("\n");
    }
    return 0;
}