Codeforces Round #693 (Div. 3)

人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想
C. Long Jumps
如果直接按照题意去模拟,肯定会超时的.
可以从后往前递推.

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int t, n;
int a[maxn];
int score[maxn];

int main()
{
        cin >> t;
        while(t--)
        {
                memset(a, 0, sizeof(a));
                memset(score, 0, sizeof(score));
                cin >> n;
                for(int i = 1; i <= n; i++)
                {
                        scanf("%d", &a[i]);
                }
                int ans = 0;
                for(int i = n; i >= 1; i--)
                {
                        if(i+a[i] <= n)
                                score[i] += a[i] + score[i+a[i]];
                        else
                                score[i] = a[i];
                        ans = max(ans, score[i]);
                }
                printf("%d\n", ans);
        }
        return 0;
}

D. Even-Odd Game
题意:
姐姐和弟弟可以轮流从一个数组中选数,姐姐先选.
姐姐如果选偶数,则得分加上这个偶数.
弟弟如果选奇数,则得分加上这个奇数.
选过的数就不能在选了.
思路:
贪心+博弈.

  1. 先从大到小排列;
  2. 姐姐弟弟从大到小轮流依次选取;
  3. 如果轮到姐姐,此时最大数为偶数,则肯定选择.为奇数,也要选,宁肯自己不得分,也不能让弟弟选到.
  4. 弟弟也是同理.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int t, n;
int a[maxn];
long long score1, score2;
bool cmp(int x, int y)
{
        return x > y;
}

int main()
{
        cin >> t;
        while(t--)
        {
                score1 = 0;
                score2 = 0;
                cin >> n;
                for(int i = 1; i <= n; i++)
                {
                        scanf("%d", &a[i]);
                }
                sort(a+1, a+n+1, cmp);
                for(int i = 1; i <= n; i ++)
                {
                        if(a[i] % 2 == 0)
                                score1 += a[i];
                        i++;
                        if(a[i] % 2 == 1 && i <= n)
                                score2 += a[i];
                }
                if(score1 > score2)
                        printf("Alice\n");
                else if(score1 < score2)
                        printf("Bob\n");
                else
                        printf("Tie\n");
        }
        return 0;
}

E. Correct Placement
题意:
n个矩形,都含有长和宽; 对于每一个矩形,找到任意1个长宽都比它小的矩形,输出它的序号.
思路:

  1. 结构体存储,每个数据存两份,长宽,宽长.
  2. 排序,一级按照h由小到大,二级按照w由大到小.
  3. 遍历,更新minW(w的最小值),并用pos记录此时的id.如果不需要更新,则此时pos即为满足当前矩形的索引.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int INF = 1e9 + 10;
struct node
{
	int h, w, id;
}op[2 * maxn];
bool cmp(node x, node y)
{
	if(x.h == y.h)
		return x.w > y.w;
	return x.h < y.h;
}
int t;
int n;
int cnt = 0;
int h, w;
int a[maxn];
int minW;

int main()
{
	cin >> t;
	while(t--)
	{
		memset(a, -1, sizeof(a));
		cin >> n;
		cnt = 0;
		for(int i = 1; i <= n; i++)
		{
			scanf("%d %d", &h, &w);
			op[cnt].h = h, op[cnt].w = w, op[cnt].id = i;
			cnt++;
			op[cnt].w = h, op[cnt].h = w, op[cnt].id = i;
			cnt++;
		}
		sort(op, op+cnt, cmp);
		minW = INF;
		int pos = -1;
		for(int i = 0; i < cnt; i++)
		{
			if(op[i].w <= minW)
			{
				minW = op[i].w;
				pos = op[i].id;
			}
			else
			{
				a[op[i].id] = pos;
			}
		}
		for(int i = 1; i <= n; i++)
			printf("%d ", a[i]);
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值