Educational Codeforces Round 72 (Rated for Div. 2) A--E

Posted by scotmcc on Fri, 06 Sep 2019 12:33:10 +0200

RANK:1868       1702 -13→ 1689  

The cf has played too badly recently. I still feel unstable. Lead to difficult problems without time to think, simple problems are not fast. The ranking is naturally very low.

A:

Firstly, we should increase our intelligence by more than one point over our strength.

Output - 1 before the point is reached.

Then divide the odds and even.

When c is even,

There are c+1 distributions, where c/2 and c/2 are zero boundaries. Intelligence c/2 or more is feasible. Consider c/2 again. For every little bit of intelligence, the difference between intelligence and strength is more than 2.

So it depends on how much intelligence is higher than the initial strength (if it is lower, the first point is more than 1 intelligence). Every two more points, you can go down a little bit less intelligence, that is, one more plan.

Attention should be paid to the scheme upper limit c+1. It's because of wa...

Then the odd number equivalence analysis can be done.

//KX
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int M = 1e5+7;
#define ls o*2
#define rs o*2+1
#define pb push_back
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a+c<=b)
		{
			puts("0");
			continue;
		}
		if(a<=b)
		{
			c-=(b+1-a),a=b+1;
		}
		int w=a-b;
		int f=(c+1)/2;
		if(c%2==0)
		{
			f++;
			printf("%d\n",min(f+(w-1)/2,c+1));
		}
		else
		{
			printf("%d\n",min(f+w/2,c+1));
		}
	}
  	return 0;
}

B:

Simple questions. I just started to think that every punch can only be used once... It took a long time.

Later, it was found that each boxing method was not used only once, and hastily wrote a hair by HACK...

Directly find the most aggressive punch. Then look for the number of attack annihilation heads minus the number of growth heads. First hit the chopping line with this punch, and then chop it off.

The details are... The biggest attack can not be killed, and all attacks are not killed more than growth. It can't be defeated.

Or, attack the most direct killing.

Then it's normal to go to the chopping line before chopping.

//KX
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int M = 100+7;
#define ls o*2
#define rs o*2+1
#define pb push_back
struct node
{
	int d,h,c;
}a[M];
bool cmp(node a,node b)
{
	return a.c>b.c;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,x;
		cin>>n>>x;
		int ma=0,id;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].d,&a[i].h);
			ma=max(ma,a[i].d);
			a[i].c=a[i].d-a[i].h;
		}
		sort(a+1,a+1+n,cmp);
		if(a[1].c<=0&&ma<x)
		{
		   puts("-1");
		   continue;
		}
		if(a[1].c>x||ma>=x)
		{
			puts("1");
			continue;
		}
		int w=a[1].c;
		x-=ma;
		int num = x/w +1;
		if(x%w!=0)num++;
		printf("%d\n",num);
	}
  	return 0;
}

C: Water. The last 30 places are 1e9. So we only need to judge 20.

Violence is enough.

//KX
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int M = 2e5+7;
#define ls o*2
#define rs o*2+1
#define pb push_back
char s[M];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		scanf("%s",s);
		int len=strlen(s);
		int n0=0,n1=0;
		int ans=0;
		for(int i=0;i<len;i++)
		{
			if(s[i]=='0')
			n0++,n1=0;
			else
			{
				int now=0;
				for(int j=i;j<=i+20;j++)
				{
					if(j>=len)break;
					now*=2;
					if(s[j]=='1')
					now++;
					if(n0+j-i+1>=now)
					ans++;
				}
				n0=0;
				n1++;
			}
		}
		printf("%d\n",ans);
	}
  	return 0;
}

D:

Firstly, only two colors are used at most, because only two colors are needed to make the rings incompletely identical.

So there are two ways:

1: First of all, I wrote. First, I built the graph, enumerated all edges, pointed to the point dfs with this edge. If I met the starting point, it showed that it was a ring, then all the edges pointing to the starting point were dyed 2.

And delete (judge whether dyeing, dyeing does not go). Enumeration can play all. ,

Or when you build a map, before adding edges, judge whether the pointing point can reach the starting point. If you can dye the edge 2 without adding, otherwise add the edge. Complexity is the same, but time theory is half the above.

2. The second method is very coquettish. Firstly, the topology judges whether there are rings or not, and whether there are rings is directly all 1.

If there are rings, all edges, U - > v. where U < V is all dyed 1, U > V is all dyed 2.

Correctness is obvious, the ring node must start from a, then to a. Because the node numbers are different, they must be wavy.

Certainly it is guaranteed that the color is not identical in the ring.

//KX
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int M = 1e4+7;
#define ls o*2
#define rs o*2+1
#define pb push_back
int cnt;
int head[M];
int ans[M];
struct EDGE
{
	int to,next,id;
}edge[M];
void add(int x,int y,int id)
{
	edge[++cnt].to=y;
	edge[cnt].next=head[x];
	edge[cnt].id=id;
	head[x]=cnt;
}
int vis[M];
bool f;
int z=0;
void dfs(int x,int u)
{
	if(vis[x])return;
	vis[x]=1;
	for(int i=head[x];i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(ans[edge[i].id]==2)continue;
//		printf("     %d -> %d    %d\n",x,v,u);
		if(v==u)ans[edge[i].id]=2;
		dfs(v,u);
	}
}
int u[M],v[M];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		add(u[i],v[i],i);
	}
	int mx=1;   
	for(int i=1;i<=m;i++)
	{
		memset(vis,0,sizeof(vis));
		for(int j=head[u[i]];j;j=edge[j].next)
		{
			int to=edge[j].to;
			if(to==v[i])
			{
				if(ans[edge[i].id]!=2)
					dfs(v[i],u[i]);
				break;
			}
		}
		//puts("ok");
		if(vis[u[i]])mx=2;
	}
	printf("%d\n",mx);
	for(int i=1;i<=m;i++)
	{
		printf("%d ",ans[i]==2?2:1);
	}
  	return 0;
}

E:

Give you n numbers.

Two operations

1 x y: Change the number x to y

2x y: Query the set of points and the minimum unbalanced set of points in the x-y interval.

The set of unbalanced points is the result of adding numbers in this set. Every bit, in the original number, has its corresponding bit.

Obviously, additionally, bitwise addition must not carry, once carried, the next must carry in order to satisfy, and then infinite cycle, must not be satisfied./

If you do not carry, it must be that one number of this is not 0, the rest are 0, in order to meet, otherwise it must be unsatisfactory.

And. The Title requires the minimum point set. We find that only two points are needed for the unbalanced point set. There is no need for more, that is, two numbers, and none of them is zero.

To sum up, we find that,

Only in the interval, each bit is processed to find the smallest number of bits that are not zero.

For example: 1230 450 607 89

Now ask for intervals 1-4.

Person: 89, 607.

Ten: 450, 89.

Hundreds: 450, 607

Thousands: 1230, INF;

Ten thousand: INF,INF

............

Each of them constitutes an unbalanced set of points, which satisfies the conditions and is the smallest set of points.

Add up to the smallest.

The result must be 450 + 89.

//KX
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int M = 2e5+7;
const ll INF = 2e9+7;
#define ls o*2
#define rs o*2+1
#define pb push_back
#define m (l+r)/2
struct node
{
	int mn[10],mc[10];
	node()
	{
		for(int i=0;i<10;i++)mn[i]=mc[i]=INF;
	}
}tr[M<<2];
node operator +(node a,node b)
{
	node tmp;
	for(int i=0;i<10;i++)
	{
		tmp.mn[i]=min(a.mn[i],b.mn[i]);
		if(a.mn[i]<b.mn[i])
			tmp.mc[i]=min(a.mc[i],b.mn[i]);
		else 
			tmp.mc[i]=min(a.mn[i],b.mc[i]);
	}
	return tmp;
}
void up(int o,int l,int r,int x,int y)
{
	if(l==r)
	{
		for(int i=0;i<10;i++)tr[o].mn[i]=tr[o].mc[i]=INF;
		for(int z=y,i=0;i<10;i++,z/=10)
			if(z%10)tr[o].mn[i]=y;
		return;
	}
	if(x<=m)up(ls,l,m,x,y);
	else up(rs,m+1,r,x,y);
	tr[o]=tr[ls]+tr[rs];
}
node qu(int o,int l,int r,int x,int y)
{
	if(x<=l&&r<=y)return tr[o];
	if(y<=m)return qu(ls,l,m,x,y);
	if(x>m)return qu(rs,m+1,r,x,y);
	return qu(ls,l,m,x,y)+qu(rs,m+1,r,x,y);
}
int main()
{
	int n,q,x;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		scanf("%d",&x),up(1,1,n,i,x);
	while(q--)
	{
		int c,x,y;
		scanf("%d%d%d",&c,&x,&y);
		if(c==1)up(1,1,n,x,y);
		else 
		{
			node tmp=qu(1,1,n,x,y);
			ll ans=INF;
			for(int i=0;i<10;i++)
				ans=min(ans,(ll)tmp.mn[i]+tmp.mc[i]);
			if(ans>=INF)puts("-1");
			else printf("%lld\n",ans);
		}
	}
  	return 0;
}

 

Topics: less REST