Educational Codeforces Round 151 (Rated for Div. 2) A和B

题目链接

A:Forbidden Integer

题意:给你整数n ,k , x ,用1 ~ k 除了x以外的数去表示n(数的和等于n )

题解 :明显可知,当x不等于1时,n能用n个1去表示 , 当x等于1时,明显当k也等于1时,无解,当k等于2时,n只有偶数才能被表示;当k大于2时,由数论知识得知,任何数都能被2 ,3叠加表示;

AC代码

#include<iostream>
#include <cstring>
#include <algorithm>

using namespace std;

void solved()
{
	int n,k,x;
    cin >> n >> k >> x;
 
    if (x != 1)
    {
        cout << "YES" << endl;
        cout << n << endl;
        for (int i = 1; i <= n; i++) cout << 1 << " ";
        cout << endl;
    }
    else
    {
        if (k == 1 || ((n & 1) && k < 3)) cout << "NO" << endl;
        else
        {
            cout << "YES" << endl;
            if (n % 2 == 0)
            {
                cout << n / 2 << endl;
                while (n)
                {
                    cout << 2 << " ";
                    n -= 2;
                }
                cout << endl;
            }
            else
            {
                cout << 1 + (n - 3) / 2 << endl;
                cout << 3 << " ";
                n -= 3;
                while (n)
                {
                    cout << 2 << " ";
                    n -= 2;
                }
                cout << endl;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cout.tie(0);
    
    int t = 1;
    cin >> t;

    while(t -- )
        solved();

    return 0;
}

B. Come Together

题意:给你A, B, C的坐标,去计算A-C和A-B的最短路径重合的路径长度

题解:只需判断B与C相对A的位置,如果BC都在A的同一方(左或右),当同时在上下方的一方时那么答案为min(abs(x[0] - x[1]) , abs(x[0] - x[2])) + min(abs(y[0] - y[1]) , abs(y[0] - y[2]));,否则min(abs(x[0] - x[1]) , abs(x[0] - x[2]));,如果BC不在同一左右方时 ,如果同时在上下方的一方则答案为min(abs(y[0] - y[1]) , abs(y[0] - y[2]));,否则没有,因为起点算一个,所以答案为上述在+1

AC代码

#include<iostream>
#include <cstring>
#include <algorithm>

using namespace std;

void solved()
{
	LL x[3] , y[3];
	for(int i = 0 ; i < 3 ; i ++ ) cin >> x[i] >> y[i];
	
	LL sum = (x[0] - x[1]) * (x[0] - x[2]);
	LL cnt = (y[0] - y[1]) * (y[0] - y[2]);
	
	LL ans = 1;
	if(sum >= 0)
	{
		if(cnt >= 0) ans += min(abs(x[0] - x[1]) , abs(x[0] - x[2])) + min(abs(y[0] - y[1]) , abs(y[0] - y[2]));
		else ans += min(abs(x[0] - x[1]) , abs(x[0] - x[2]));
	}else 
	{
		if(cnt >= 0) ans += min(abs(y[0] - y[1]) , abs(y[0] - y[2]));
		else ans = 1;
	}
	
	cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cout.tie(0);
    
    int t = 1;
    cin >> t;

    while(t -- )
        solved();

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值