Educational Codeforces Round 77 (Rated for Div. 2) 题解

题目链接:https://codeforces.com/contest/1260

 

A - Heating


 #include
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair  pa;
const int mx = 1e4 + 10;
const int mod = 1e9 + 7;
int main()
{  
	int n;
	scanf("%d",&n);
	while (n--) {
		int u,v;
		scanf("%d%d",&u,&v);
		int reg = v / u;
		int mv = v % u;
		ll ans = 1ll*mv*(reg+1)*(reg+1);
		ans += 1ll*(u-mv)*reg*reg;
		printf("%lld\n",ans);
	}
    return 0;
}

B - Obtain Two Zeroes

设一个2*x+y = a,x+2*y = b,然后联立方程解x,y。

#include
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair  pa;
const int mx = 1e4 + 10;
const int mod = 1e9 + 7;
int main()
{  
	int n;
	scanf("%d",&n);
	while (n--) {
		int a,b;
		scanf("%d%d",&a,&b);
		int u = 2*a - b;
		if (u >= 0 && u % 3 == 0) {
			int v = u / 3;
			if (v > b) puts("NO");
			else puts("YES");
		} else 
			puts("NO");
	}
    return 0;
}

C - Infinite Fence

设b>a,那么在一个区间[x*b,x*b+b]里面a的倍数最前面一次出现肯定是gcd(b,a)

然后就可以求出一个b区间里面最多放几个a了

#include
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair  pa;
const int mx = 1e4 + 10;
const int mod = 1e9 + 7;
int main()
{  
	int n;
	scanf("%d",&n);
	while (n--) {
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		int G = __gcd(a,b);
		if (a > b) swap(a,b);
		int g = (b-G-1) / a + 1;
		puts(g>=c?"REBEL":"OBEY");
	}
    return 0;
}

D - A Game with Traps

二分答案,然后发现被覆盖的路径要走三遍,然后就OK了

#include
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair  pa;
const int mx = 2e5 + 10;
const int mod = 1e9 + 7;
struct node {
	int l,r;
	int d;
	bool operator < (node A) const
	{
		return r < A.r;
	}
}s[mx];
int sum[mx];
int a[mx];
int n,m,K,t;
bool check(int mid) {
	for (int i=0;i<=n;i++) sum[i] = 0;
	for (int i=1;i<=K;i++) {
		if (s[i].d > mid) {
			sum[s[i].l]++;
			sum[s[i].r+1]--;
		}
	}
	int len = 0;
	for (int i=1;i<=n;i++) {
		sum[i] += sum[i-1];
		len += (sum[i] != 0);
	}
	int ret = len*3 + (n+1-len);
	return ret <= t;
}
int main()
{  
	scanf("%d%d%d%d",&m,&n,&K,&t);
	int l = 0,r = m;
	for (int i=1;i<=m;i++) 
		scanf("%d",a+i);
	sort(a+1,a+1+m,greater());
	for (int i=1;i<=K;i++) {
		scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);
	}
	a[0] = 1e6;
	while (l < r) {
		int mid = l+r+1>>1;
		if (check(a[mid]))
			l = mid;
		else 
			r = mid - 1;
	} 
	printf("%d\n",l);
    return 0;
}

E - Tournament

首先每轮打的人的序号肯定是递增了,然后dp一下发现前提条件是打第i轮的时候已经减少了2^i - 2个人,然后就可以dp了。

#include
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair  pa;
const int mx = 1<<19;
const ll inf = 1e18;
const int mod = 1e9 + 7;
ll dp[mx][19];
int pr[30];
int a[mx];
int main()
{  
	int n,pos;
	scanf("%d",&n);
	pr[0] = 1;
	for (int i=1;i<30;i++)
		pr[i] = pr[i-1]*2;
	int mi = 1e9,bit = 0;
	for (int i=1;i<=n;i++) {
		scanf("%d",a+i);
		mi = min(a[i],mi);
		if (mi != -1) a[i] = 0;
		if (a[i] == -1) pos = i;
	}
	while ((1<

 

你可能感兴趣的:(DP,二分系列,思维题)