Codeforces Round #720 (Div. 2)
程序员文章站
2024-03-21 13:10:52
...
Codeforces Round #720 (Div. 2)
A. Nastia and Nearly Good Numbers
input
3
5 3
13 2
7 11
output
YES
10 50 60
YES
169 39 208
YES
28 154 182
题意:
输入a,b。判断能否找出一个好数字(a,b共同的倍数),两个几乎好数字(只是a的倍数)。并且满足其中两个数相加等于第三个数。
思路:
题意很明确,就直接构造就行,x=a(x几乎好数字,只是a的倍数),y=a * b(y好数字,a,b的倍数),z=a+(a * b)(z几乎好数字,只是a的倍数),并且满足x+y=z;
这里需要特判b=1,因为任何数都是1的倍数,所以找不到两个几乎好数字。
AC代码
//x+y==z
//1个好数字(a与b的倍数),两个几乎好数字(只是a倍数)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll a,b,t;
cin>>t;
while(t--)
{
cin>>a>>b;
if(b==1)
{
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
cout<<a<<" "<<a*b<<" "<<a+(a*b)<<endl;
}return 0;
}
input
2
5
9 6 3 11 15
3
7 5 13
output
2
1 5 11 9
2 5 7 6
0
题意:
需要用最多n-1个操作数,来构造一个相邻互质的数组
思路:
由题意可知,最小的位置上的数绝对是构造完的数列中最小的那个数,所以最小的数肯定要保留,我们可以用这个数直接操作n-1次,使相邻位差为1
AC代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e9+10;
int main()
{
int t,n,a[200050];
cin>>t;
while(t--)
{
cin>>n;
int minn=N;
int k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(minn>a[i])
{
minn=a[i];
k=i;
}
}
cout<<n-1<<endl;
for(int i=k+1,j=1;i<=n;i++,j++)
{
cout<<k<<" "<<i<<" "<<minn<<" "<<minn+j<<endl;
}
for(int i=k-1,j=1;i>=1;i--,j++)
{
cout<<k<<" "<<i<<" "<<minn<<" "<<minn+j<<endl;
}
}return 0;
}
推荐阅读
-
Codeforces Round #720 (Div. 2)
-
Codeforces Round #720 (Div. 2)
-
Codeforces Round #446 (Div. 2) B(数论,模拟,gcd,最大公约数)
-
C. Balanced Bitstring(字符串+思维) Codeforces Round #668 (Div. 2)
-
Codeforces Round #668 (Div. 2)-C. Balanced Bitstring
-
Codeforces Round #610 (Div. 2) E The Cake Is a Lie(拓扑排序)
-
Educational Codeforces Round 55 (Rated for Div. 2)总结
-
Educational Codeforces Round 55 (Rated for Div. 2) B
-
Educational Codeforces Round 55 (Rated for Div. 2)
-
【Codeforces】 Round #627 Div. 3 (补题)