Codeforces Round #276 (Div. 2)

A - Factory :每天结束后  a = a + a % m;然后每次对a进行判断即可

#include<stdio.h>
#include<string.h>
#define N 100005

int c[N];

int main()
{
    int a, m;
    while(~scanf("%d%d", &a, &m))
    {
        memset( c, 0, sizeof( c ));
        bool f = 0;
        while(1)
        {
            a = a + a % m;
            a %= m;
            if ( a == 0 )
            {
                f = 1;
                break;
            }
            else if(c[a])
            {
                break;
            }
            else
                c[a] = 1;
        }
        printf("%s\n", f? "Yes": "No");
    }
    return 0;
}

B: Valuable Resources :给出n个点,求覆盖这n个点的最小正方形,其中正方形的边与坐标轴平行

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

typedef __int64 ll;

int main()
{
    ll x, xx, y, yy;
    int n;
    while(~scanf("%d", &n))
    {
        ll q, w;
        scanf("%I64d%I64d", &q, &w);
        x = xx = q;
        y = yy = w;
        n--;
        while(n--)
        {
            scanf("%I64d%I64d", &q, &w);
            x = min(q, x);
            xx = max(q, xx);
            y = min(y, w);
            yy = max(w, yy);
        }
        printf("%I64d\n", max(xx - x, yy - y) * max(xx - x, yy - y));
    }
    return 0;
}

C - Bits:求l ~ r里面二进制中1最多的数,且尽可能小。

从l开始,每次将二进制里为0的变为1,看看有没有超出范围, (>r)超出的话直接输出即可。

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

typedef __int64 ll;

int c[100];

ll pow(ll x, ll y)
{
	ll w = 1;
	if( y == 0 )
		return 1;
	while(y--)
		w *= x;
	return w;
}

int main()
{
	ll l, r;
	int n;
	while(~scanf("%d", &n))
	{
		while(n--)
		{
			scanf("%I64d%I64d", &l, &r);
			ll tmp = l;
			memset( c, 0, sizeof(c) );
			int cnt = 0;
			while(tmp)
			{
				c[++cnt] = tmp % 2;
				tmp /= 2;
			}
			ll ans = l;
			int pos = 1;
			while ( ans <= r )
			{
				if( c[pos] == 0 )
				{
					if( ans + (ll)pow(2, pos-1 ) > r )
					{
						printf("%I64d\n", ans);
						break;
					}
					else
					{
						ans = ans + pow(2, pos-1 );
					}
				}
				pos ++;
			}
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值