Codeforces Round #818 (Div. 2)

A

Madoka and Strange Thoughts

题意:求1<=a,b<=n中,满足lcm(a,b)/gcd(a,b)<=3的(a,b)个数

思路:lcm(a,b)/gcd(a,b)=a/gcd(a,b) * b/gcd(a,b),由于a/gcd,b/gcd都是整数,对于乘积小于等于3无非就1*1,1*2,1*3,3*1,2*1五种情况。首先1*1的情况,a=b=gcd(a,b),共n种;1*2的情况,a=gcd, b=2*a,有n/2种(向下取整);1*3的情况,a=gcd,b=3*a,有n/3种。再考虑对称的情况,所以答案为n+2*(n/2+n/3) 

#include <bits/stdc++.h>
#define lowbit(x) x&(-x)
#define ios std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define PII pair<int,int>
typedef long long ll;
const int N=1e6+10;
const int inf=0x3f3f3f3f;

using namespace std;
int n;
void solve()
{
	cin>>n;
	cout<<n+n/2*2+n/3*2<<'\n';
}
int main()
{
	//ios;
	int _t=1;
	cin>>_t;
	while(_t--) solve();
	system("pause");
	return 0;
}

B

Madoka and Underground Competitions

题意:给定一个n*n的方格,我们要保证每行每列中每连续k个格中至少要有一个x,其余为.,现在告诉我们第r行c列是一个x,让我们输出一种方案使得我们填充的x数目尽量少

思路:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,k,r,c;
		scanf("%d%d%d%d",&n,&k,&r,&c);
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			if((i+j+n*n-r-c)%k==0) printf("X");
			else printf(".");
			puts("");
		}
		puts("");
	}
	return 0;
}

C

Madoka and Formal Statement

题意: 给定长度为n的数组a和b,问能否通过以下操作将a变成b。

第i个位置的元素可以+1的充分必要条件是第i+1个位置的元素值大于等于当前元素,特殊地,如果i=n,那么i+1看作1

思路:

#include <bits/stdc++.h>
#define lowbit(x) x&(-x)
#define ios std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define PII pair<int,int>
typedef long long ll;
const int N=1e6+10;
const int inf=0x3f3f3f3f;

using namespace std;
int n;
int a[N],b[N];
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    bool flag=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]>b[i])
        {
            flag=0;
            break;
        }
        if(b[i]>a[i]&&b[i]>b[(i+1)%n]+1)
        {
            flag=0;
            break;
        }
    }
    if(flag) puts("YES");
    else puts("NO");
}
int main()
{
    //ios;
    int _t=1;
    cin>>_t;
    while(_t--) solve();
    system("pause");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值