其他分享
首页 > 其他分享> > Codeforces Round #720 (Div. 2) 题解

Codeforces Round #720 (Div. 2) 题解

作者:互联网

\(PS:\)跟\(SB\)一样看错题,\(A\)和\(B\)快\(wa\)哭了。状态不佳,下次再战。
比赛链接

A. Nastia and Nearly Good Numbers

题意

给定两个数字\(A\)和\(B\),要求找到三个不同的数\(x,y,z\)使得\(x+y=z\)成立且其中一个数能被\(A * B\)整除,其余两个能被\(A\)整除。

思路

首先我们可以知道当\(m=1\)时一定无解,因为此时\(A * B=A\),即三个数都能被\(A * B\)整除,当\(m\neq 1\)时,原式等价于\(a * A + b * A=A * B * c\),则两边约去\(A\)得到\(a+b=B * c\),即我们一定可以找到一个数\(c\)使得\(a+b=B * c\)且\(a\neq b\neq B * c\),不妨取\(c=10\)。

代码

int main() 
{
    int T;
    cin >> T;
    while (T -- )
    {
        LL a, b;
        cin >> a >> b;
 
        if (b == 1) 
        {
            puts("NO");
            continue;
        }
        
        for (int i = 1; i <= 10 * b - 1; i ++ ) 
        {
            if (i != 10 - i && 10 * b != i && 10 * b != 10 - i)
            {
                puts("YES");
                cout << a * i << ' ' << a * (10 * b - i) << ' ' << 10 * b * a << endl;
                flag = false;
                break;
            }
        }
    }
 
    return 0;
}

B. Nastia and a Good Array

题意

给定一个长度为\(n\)的数组,要求以不超过\(n\)次的改变操作使其满足\(gcd(a _ {i-1},a_i)=1,(2\leq i\leq n)\),当且仅当两个下标\(1\leq i,j\leq n\)和两个数\(x,y\),使得\(min(a_i,a_j)=min(x,y)\)时可以将\(a_i=x,a_j=y\)。输出时\(i\)在前。
注意:没有限制时最小的操作数。

思路

则可以每次选择最小的数和其他的数,并将其他的数变成相邻的数加\(1\)或减\(1\)。

代码

const int N = 100010;

int n, m;
int g[N];

int main()
{
	int T;
	cin >> T;
	while(T -- )
	{
		cin >> n;

        int t, minv = 0x3f3f3f3f;
        for (int i = 1; i <= n; i ++ ) 
        {
            cin >> g[i];
            if (g[i] < minv) 
            {
               t = i;
               minv = g[i]; 
            }
        }

        cout << n - 1 << endl;
        for (int i = t + 1; i <= n; i ++ ) 
            g[i] = g[i - 1] + 1, cout << t << ' ' << i << ' ' << minv << ' ' << g[i]<< endl;
        for (int i = t - 1; i >= 1; i -- ) 
            g[i] = g[i + 1] + 1, cout << t << ' ' << i << ' ' << minv << ' ' << g[i] << endl;
	}

    return 0;
}

C. Nastia and a Hidden Permutation

交互题,明天在补,2021年5月8日02:52:33,太晚了。

标签:int,题解,Nastia,cin,Codeforces,leq,--,Div,neq
来源: https://www.cnblogs.com/wanshu/p/14743361.html