Codeforces Round #576 (Div. 2) C-F

链接: https://codeforces.com/contest/1199
C. MP3(尺取+贪心)
题面:
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.

If there are exactly K distinct values in the array, then we need k=⌈log2K⌉ bits to store each value. It then takes nk bits to store the whole file.

To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l≤r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don’t change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.

Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.

We remind you that 1 byte contains 8 bits.

k=⌈log2K⌉ is the smallest integer such that K≤2k. In particular, if K=1, then k=0.
(1≤n≤4e5, 1≤I≤108)
题意:
给你一个数组,总共K个不同的元素,储存整个数组需要n*⌈log2K⌉ bits, 现给你一个8 * I bits,要你最少改变多少个元素,使得足够储存整个数组
思路: 首先从数据范围可以适当缩小一下范围,因为顶多只有4e5个不同的元素,所以(8*I)/n>19就足够存了,直接结束。
若肯定需要删除的情况下,我们可以sort一下,然后双指针不断找最小需要删除的个数,复杂度O(nlogn+n)

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=4e5+5;
int a[N];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	k=8*k/n;
	if(k>19||(1<<k)>n)
	{
		puts("0");
		return 0;
	}
	k=(1<<k);
	sort(a+1,a+1+n);
	int l=1,r=1;
	int cnt1=1;
	int ans=0x3f3f3f3f;
	while(r<=n)
	{
		while(cnt1>k&&l<=r)
		{
			l++;
			if(a[l]!=a[l-1])
			{
				cnt1--;
			}
		}
		ans=min(ans,n-(r-l+1));
		r++;
		if(a[r]!=a[r-1])
			cnt1++;
	}
	cout<<ans<<endl;
	return 0;
}

D. Welfare State:
题面:
There is a country with n citizens. The i-th of them initially has ai money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.

Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don’t send a receipt.

You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
题意:
给你一个数组,然后有多次操作,操作1将指定位置的数变成x,操作2是把所有小于x的数变成x,输出最终的数组
思路: 此题要是用线段树做的话,极大可能TLE第35个点,所以此题还有更加快速的做法复杂度O(n+q)
我们可以意识到在某个位置上操作1前面的操作2都是无效的,因为会被后来的操作1覆盖,而且要是操作1后面的操作2比操作1小也是无效的,所以我们只需注意在操作1后面的操作2,且比较x的大小即可
所以对于操作1我们可以直接在原数组修改,并记录修改的序号,我们将操作2另外存起来,最后由后往前覆盖操作2,后缀取max,最终比较每个位置上最后一次操作1的修改与该次操作1后面的操作2最大值比较即可

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+5;
int a[N],b[N],flag[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int op,p,x;
		scanf("%d",&op);
		if(op==1)
		{
			scanf("%d%d",&p,&x);
			flag[p]=i;
			a[p]=x;
			continue;
		}
		scanf("%d",&x);
		b[i]=x;
	}
	for(int i=q;i>0;i--)
	{
		b[i]=max(b[i],b[i+1]);
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]<b[flag[i]+1])
			a[i]=b[flag[i]+1];
		printf("%d ",a[i]);
	}
	puts("");
	return 0;
}

E. Matching vs Independent Set
题面:
You are given a graph with 3⋅n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.

A set of edges is called a matching if no two edges share an endpoint.

A set of vertices is called an independent set if no two vertices are connected with an edge.
Print your answer for each of the T graphs. Output your answer for a single graph in the following format.

If you found a matching of size n, on the first line print “Matching” (without quotes), and on the second line print n integers — the indices of the edges in the matching. The edges are numbered from 1 to m in the input order.

If you found an independent set of size n, on the first line print “IndSet” (without quotes), and on the second line print n integers — the indices of the vertices in the independent set.

If there is no matching and no independent set of the specified size, print “Impossible” (without quotes).

You can print edges and vertices in any order.
题意: 给你一个无向图,有3*n个点,问你是否能找到n个不相连的点或者n条不共点的边
思路: 因为有3n个点,所以无论怎样满足n个不相连的点,所以随便搞搞就可以了,一开始还想写个dfs01染色来求

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e5+5;
int vis[3*N];
vector<int>ma;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
 
		ma.clear();
		int n,m,cnt=0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=3*n;i++)
		{
			vis[i]=false;
		}
		for(int i=1;i<=m;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			if(!vis[u]&&!vis[v])
			{
				vis[u]=1;
				vis[v]=1;
				ma.push_back(i);
			}
		}
		if(ma.size()>=n)
		{
			puts("Matching");
			for(int i=0;i<n;i++)
				printf("%d ",ma[i]);
			puts("");
			continue;
		}
		puts("IndSet");
		for(int i=1;i<=3*n;i++)
			if(!vis[i]&&cnt<n)
			{
				cnt++;
				printf("%d ",i);
				if(cnt==n)
					break;
			}
		puts("");
	}
	return 0;
}

F. Rectangle Painting 1:
题解链接: https://blog.csdn.net/qq_42819598/article/details/98650640

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值