首页 > 其他分享 >Educational Codeforces Round 157 (Rated for Div. 2) 复盘

Educational Codeforces Round 157 (Rated for Div. 2) 复盘

时间:2024-04-17 20:37:35浏览次数:17  
标签:count Educational Rated 157 ++ i0 ll last1 ans

又是vp的稀烂的一场。

A没问题。被B一道800卡了。

但是确实非常简单,就是从式子上入手,让\(|x_1-x_2|+|y_1-y_2|\)最小就可以了。
所以就把两维度分开来看,这两维之间的距离是不会影响代价的,这是曼哈顿距离的特点。
那么就很明显了,就是从中间分开。

但是我vp的时候并没有看出来。而是在猜结论。因为我不知道怎么想,但是事实上我就应该直接分析我的答案是什么样的,然后得出结论。我没有去思考,这非常不好。这题我感觉就是这样的。我其实可以适当的跳过一些证明,猜一些小结论。比如这题,我开始的时候就被分成两组这个东西给拉扯住了,没有往下想的思路了。很要命,但是事实上这个根本就不是什么很难的东西。以后看题可以跟注重从结果出发来分析题目。

然后就是C,更是依托。赛时写了160行。只能说我的代码能力是更强了,这种事都干得出来。。。
然而cf的c题根本就不会让你写这么多。我其实就没有仔细分析题目就去写了。
我应该去思考一下,另一半到底应该满足写什么条件,然后在根据这条件去维护一些东西。

很明显,满足的条件就是1.长度 2.数值和。如果我知道了另一半所需要用的长度,那么,那一边的数值和也就知道了。
那这不就很好维护吗?直接用一个数组就可以了。然后我就把5个情况全部分开。。写傻了。。然后还wa了,都不知道错哪里了。

好了,现在知道了。160行写错了一行,就死了。
服了,但凡做法简单点。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read() {
	char c=getchar();ll a=0,b=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;return a*b;
}
ll n;
string s[200001];
ll f[351][351];
ll count(string a,ll x)
{
	ll ans=0;
	for(ll i=0;i<x;i++)ans+=a[i]-'0';
	return ans;
	
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("2.out","w",stdout);
//	ll T=read();
//	while(T--)
	{
		n=read();
		for(ll i=1;i<=n;i++)
		{
			cin>>s[i];
//			cout<<count(s[i],s[i].size())<<endl;
		}
		memset(f,0,sizeof(f));
		ll ans=0;
		for(ll i=1;i<=n;i++)
		{
			if(s[i].size()==2)
			{
				f[count(s[i],2)][0]++;
			}
			else
			if(s[i].size()==4)
			{
				if(count(s[i],4)-count(s[i],1)>0)
				f[count(s[i],1)][count(s[i],4)-count(s[i],1)]++;
				f[0][count(s[i],4)]++;
			}
		}
		for(ll i=1;i<=n;i++)
		{
			if(s[i].size()==2)
			{
				ans+=f[count(s[i],2)][0];
				for(ll j=1;j<=9;j++)
				{
					ans+=f[j][count(s[i],2)+j];
				}
			}
			if(s[i].size()==4)
			{
				ll forth=count(s[i],4)-count(s[i],3);
				if(count(s[i],3)-forth>0)ans+=f[count(s[i],3)-forth][0];//2
				ans+=f[0][count(s[i],4)];
			}
		}
		memset(f,0,sizeof(f));
		for(ll i=1;i<=n;i++)//1
		{
			if(s[i].size()==1)
			{
				f[count(s[i],1)][0]++;
			}
			if(s[i].size()==3)
			{
				if(count(s[i],3)-count(s[i],1)>0)f[count(s[i],1)][count(s[i],3)-count(s[i],1)]++;
			}
			if(s[i].size()==5)
			{
				if(count(s[i],5)-count(s[i],2)>0)f[count(s[i],2)+50][count(s[i],5)-count(s[i],2)]++;
			}
		}
		for(ll i=1;i<=n;i++)
		{
			if(s[i].size()==1)
			{
				ans+=f[count(s[i],1)][0];
				for(ll k=1;k<=9;k++)
				{
					ans+=f[k][k+count(s[i],1)];
				}
				for(ll j=2;j<=18;j++)
				{
					ans+=f[j+50][j+count(s[i],1)];
				}
			}
		}
//		cout<<ans<<endl;
		memset(f,0,sizeof(f));
		for(ll i=1;i<=n;i++)//3
		{
			if(s[i].size()==1)
			{
				f[count(s[i],1)][0]++;
			}
			if(s[i].size()==3)
			{
				f[0][count(s[i],3)]++;
			}
			if(s[i].size()==5)
			{
				if(count(s[i],5)-count(s[i],1)>0)
				f[count(s[i],1)][count(s[i],5)-count(s[i],1)]++;
			}
		}
		for(ll i=1;i<=n;i++)
		{
			if(s[i].size()==3)
			{
				ll last1=count(s[i],3)-count(s[i],2);
				ans+=f[0][count(s[i],3)];// 3
//				cout<<ans<<endl;
				if(count(s[i],2)-last1>0)
				ans+=f[count(s[i],2)-last1][0];// 1
//				cout<<ans<<endl;
				for(ll j=1;j<=9;j++)
				{
					ans+=f[j][count(s[i],3)+j];// 5
				}
//				cout<<ans<<endl;
			}
		}
//		cout<<ans<<endl;
		memset(f,0,sizeof(f));
		for(ll i=1;i<=n;i++)//5
		{
			if(s[i].size()==1)
			{
				f[count(s[i],1)][1]++;
			}
			if(s[i].size()==3)
			{
				f[count(s[i],3)][3]++;
			}
			if(s[i].size()==5)
			{
				f[count(s[i],5)][5]++;
			}
		}
		for(ll i=1;i<=n;i++)
		{
			if(s[i].size()==5)
			{
				ll last2=count(s[i],5)-count(s[i],3);
				if(count(s[i],3)-last2>0)ans+=f[count(s[i],3)-last2][1];
				ll last1=count(s[i],5)-count(s[i],4);
				if(count(s[i],4)-last1>0)ans+=f[count(s[i],4)-last1][3];
				ans+=f[count(s[i],5)][5];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*

2 
2 942 

*/

标签:count,Educational,Rated,157,++,i0,ll,last1,ans
From: https://www.cnblogs.com/HLZZPawa/p/18141691

相关文章

  • Educational Codeforces Round 158 (Rated for Div. 2) C
    链接一个为了1300的题目而写的总结。挺可怕的。赛时写了一个按位贪心,但是假了。我现在就是不知道,如果做法想假了,waontest2到底要怎么来判断。我找不到反例,那就只能坐着等死。真的太难受了。要是做题能不能做对全看的想到的第一个做法对不对,和他有没有错在一些很离谱的地方,这我......
  • VMware Tanzu Kubernetes Grid Integrated Edition (TKGI) 1.19 - 运营商 Kubernetes
    VMwareTanzuKubernetesGridIntegratedEdition(TKGI)1.19-运营商Kubernetes解决方案Kubernetes-basedcontainersolutionwithadvancednetworking,aprivatecontainerregistry,andlifecyclemanagement请访问原文链接:https://sysin.org/blog/vmware-tkgi/,查......
  • Educational Codeforces Round 164 (Rated for Div. 2)
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1954本来有机会上大分但是唐了E没调出来呃呃。小号比大号分高了呃呃以后想休闲直接打大号了哈哈A数学。若要将\(n\)个位置全部涂成颜色\(i\),则一定要修改\(n-\operatorname{count}(i)\)......
  • 洛谷题单指南-数学基础问题-P1572 计算分数
    原题链接:https://www.luogu.com.cn/problem/P1572题意解读:计算分数+、-运算的结果。解题思路:根据题目要求,逐项计算并约分,则不会超int,问题就比较直接了定义a1/b1为前一项的分子分母,a2/b2为当前项的分子分母依次遍历字符串,处理出分子和分母,本题的关键其实是字符串的处理当读取......
  • [题解](A-G)Atcoder Educational DP Contest(更新中)
    AtcoderEducationalDPContest\(\textbf{A.Frog1}\)对于一块石头\(i(3\lei\leN)\),\(i-1\)和\(i-2\)均能到达。用\(f[i]\)表示跳到第\(i\)个石头用的最小体力消耗:\[f[i]=min(abs(h[i]-h[i-1])+f[i-1],abs(h[i]-h[i-2])+f[i-2])\qquadi\ge3\]时间复杂度\(O(n)\)。......
  • Educational Codeforces Round 164 (Rated for Div. 2) D
    因为理解错了题目导致我没错出来。我理解为有两个人取球,每个人每次都是取一组,也就是一组的球必须要放在一个人手里。。因为我之前做的一个背包是这个样子的。这就导致了,我认为每次转移所需要的信息是比实际要的多很多的,直接导致我没法设计一个正常的dp。然后炸了。。。好烦。。......
  • P1157 组合的输出
    P1157组合的输出题目排列与组合是常用的数学方法,其中组合就是从\(n\)个元素中抽出\(r\)个元素(不分顺序且\(r\len\)),我们可以简单地将\(n\)个元素理解为自然数\(1,2,\ldots,n\),从中任取\(r\)个数。现要求你输出所有组合。例如\(n=5,r=3\),所有组合为:\(123,124,125......
  • [CF1954] Educational Codeforces Round 164 (Rated for Div. 2) 题解
    [CF1954]EducationalCodeforcesRound164(RatedforDiv.2)题解A.PaintingtheRibbon最优策略是染\(\lceil\dfrac{n}{m}\rceil\)个颜色,然后Bob会把剩下的都染成这个颜色voidwork(){intn,m,k,c;cin>>n>>m>>k;c=(n+m-1)/m;......
  • [CF1942] CodeTON Round 8 (Div. 1 + Div. 2, Rated, Prizes! A~E 题解
    [CF1942]CodeTONRound8(Div.1+Div.2,Rated,Prizes!A~E题解A.FarmerJohn'sChallenge只有两种情况,一种是单调递增,这时\(k=1\),另一种是所有数都相同,这时\(k=n\)。B.BessieandMEX首位可以确定,然后从前往后增量构造\(p\)即可。voidwork(){cin>>......
  • Educational Codeforces Round 36 (Rated for Div. 2)
    EducationalCodeforcesRound36(RatedforDiv.2)A直接枚举即可#include<bits/stdc++.h>intmain(){std::ios::sync_with_stdio(false);std::cin.tie(nullptr);intn,k;std::cin>>n>>k;intans=1e9;for(int......