Codeforces Round #262

div. 2

A. Vasya and Socks

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d", &n, &m);
	int last=0;
	int ans=0;
	while(n)
	{
		n--;
		last++;
		ans++;
		if(last == m)
		{
			last = 0;
			n++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

B. Little Dima and Equation

#include <bits/stdc++.h>
using namespace std;
#define ll __int64
#define inf 1000000000
ll p[100];
int main()
{
	int a, b, c, li=0;
	scanf("%d%d%d", &a, &b, &c);
	for(int i = 1; i <= 81; i++)
	{
		ll si = (ll)b * pow(i*1.0, a) + c;
		int s=0;
		ll sum = si;
		while(sum)
		{
			s += sum%10;
			sum/=10;
		}
		if(si > inf) continue;
		if(s == i)
		{
			li++; 
			p[li] = si;
		}
	}
	printf("%d\n", li);
	for(int i = 1; i <= li; i++)
	{
		if(i!=li) printf("%I64d ", p[i]);
		else printf("%I64d\n", p[i]);
	}
	return 0;
}

C. Present

n盆花,浇水可以浇m天,每次浇连续的w盆

每盆花有一个初始值a

浇一次水a加1

最终要使n盆花的最小值最大

求这个最大值

用折半查找的方法做

根据题目,我们可以知道a的范围  1<=a<=10^9+10^5

折半查找a

#include <bits/stdc++.h>
using namespace std;
#define inf 100005
#define maxn 1e9+1e5
#define ll __int64
ll p[inf];
ll s[inf];
int n, m, w;
int solve(ll num)
{
	memset(s, 0, sizeof(s));
	ll last = 0;
	ll wi = 0;
	for(int i = 1; i <= n; i++)
	{
		last += s[i];
		if(p[i] +last < num) 
		{
			s[(i+w)>n?n+1:i+w] -= (num-p[i]-last);
			wi += (num-p[i]-last);
			last += (num-p[i]-last);
			if(wi > (ll)m) return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d%d%d", &n, &m, &w);
	for(int i = 1; i <= n; i++)
	{
		scanf("%I64d", &p[i]);
	}
	ll l = 1, r = maxn;
	ll ans = 0;
	while(l <= r)
	{
		ll mid = (l+r) >> 1;
		int s = solve(mid);
		if(s == 1)
		{
			l = mid+1;
			ans = max(ans , mid);
		}
		else
		{
			r = mid-1;
		}  
	}
	printf("%I64d\n", ans);
	return 0;
}

D. Little Victor and Set

在l~r中,选出x个组成数列s[ ](1<=x<=k),使得s[1]^s[2]^s[3]^……^s[x]最小

小知识点:(2*x) ^ (2*x+1) = 1

分别讨论r-l+1  和  k

比较烦的就是s[]包含的元素只有3个的时候

3个元素的规律应当是这样子的

1100……000

1011……111

0111……111

#include <bits/stdc++.h>
using namespace std;
#define ll __int64
int main()
{
	ll l, r, k;
	scanf("%I64d%I64d%I64d", &l, &r, &k);
	if(k == 1 || r - l + 1 == 1)
	{
		printf("%I64d\n1\n%I64d\n", l, l);
		return 0;
	}
	if(r - l + 1 == 2)
	{
		if(l&1) 
		{
			ll ans = l^r;
			if(l < ans) printf("%I64d\n1\n%I64d\n", l, l);
			else printf("%I64d\n2\n%I64d %I64d\n", l^r, l, r);
		}
		else printf("1\n2\n%I64d %I64d\n", l, r);
		return 0;
	}
	if(r - l + 1 == 3)
	{
		ll a, b;
		if(l&1) a = l+1, b = r;
		else a = l, b = l+1;
		if(k == 2)
		{
			printf("1\n2\n%I64d %I64d\n", a, b);
			return 0;
		}
		else
		{
			ll ans = l^(l+1);
			ans = ans^r;
			if(ans == 0)
			{
				printf("0\n3\n%I64d %I64d %I64d\n", l, l+1, r);
				return 0;
			}
			else
			{
				printf("1\n2\n%I64d %I64d\n", a, b);
				return 0;
			}
		}
	}
	if(r - l + 1 == 4)
	{
		if(k == 2)
		{
			ll a, b;
			if(l&1) l++;
			printf("1\n2\n%I64d %I64d\n", l, l+1);
			return 0;
		}
		else
		{
			if(l&1 || k == 3)
			{
				ll a = l, b = l+1, c = l+2, d = l+3;
				ll ans = a^b;
				ans = ans^c;
				if(ans == 0)
				{
					printf("0\n3\n%I64d %I64d %I64d\n", a, b, c);
					return 0;
				}
				ans = a^b;
				ans = ans^d;
				if(ans == 0)
				{
					printf("0\n3\n%I64d %I64d %I64d\n", a, b, d);
					return 0;
				}
				ans = a^c;
				ans = ans^d;
				if(ans == 0)
				{
					printf("0\n3\n%I64d %I64d %I64d\n", a, c, d);
					return 0;
				}
				ans = b^c;
				ans = ans^d;
				if(ans == 0)
				{
					printf("0\n3\n%I64d %I64d %I64d\n", b, c, d);
					return 0;
				}
				if(l&1) l++;
				printf("1\n2\n%I64d %I64d\n", l, l+1);
			}
			else printf("0\n4\n%I64d %I64d %I64d %I64d\n", l, l+1, l+2, l+3);
		}
		return 0;
	}
	if(r - l + 1 > 4)
	{
		if(k == 2)
		{
			ll a, b;
			if(l&1) a = l+1, b = l+2;
			else a = l, b = l+1;
			printf("1\n2\n%I64d %I64d", a, b);
			return 0;
		}
		if(k == 3)
		{
			ll x=-1,y,z;
		    for(ll i=3; i<=r; i=i<<1)
			{
		        if((i^(i-1))>=l)
				{
		            x=i;
		            y=i - 1;
		            z=i^(i-1);
		            break;
		        }
		    }
			if(x!=-1)
			{
		        printf("0\n3\n%I64d %I64d %I64d\n",x,y,z);
		    }
		    else 
			{
		        if(l&1) l++;
		        printf("1\n2\n%I64d %I64d\n",l,l+1);
		    }
		    return 0;
		}
		if(k >= 4)
		{
			ll a, b, c, d;
			if(l&1) l++;
			printf("0\n4\n%I64d %I64d %I64d %I64d\n", l, l+1, l+2, l+3);
		}
	}
	return 0;
}

E. Roland and Rose


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值
>