CodeForces Round 220

19 篇文章 0 订阅

第二题怎么交怎么错,到最后竟然是题目错了,哎,齐葩。

A。Inna and Pink Pony

第一题最后过了ST的只有不到200个...我的那份代码挂了= =

挂在如果一步都不能动,那么是不可以到的

这题意思是给你个棋盘,里面(i,j)处放了个糖,你可以把这个糖这样移动

  • move the candy from position (x, y) on the board to position (x - a, y - b);
  • move the candy from position (x, y) on the board to position (x + a, y - b);
  • move the candy from position (x, y) on the board to position (x - a, y + b);
  • move the candy from position (x, y) on the board to position (x + a, y + b).
如果可以移到角上,就获胜,输出最小步数。

如果棋盘行数小于a,或者列数小于b,那么直接pass

如果一开始就在角上,那就是0

先算到角的横纵距离,如果有不是a或者b的倍数的,跳过

然后算出倍数是几。如果相差不是偶数的跳过。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define fst first
#define sec second
typedef pair<int,int> P;
int main()
{
	int n,m,x,y,a,b;
	scanf("%d%d%d%d%d%d",&n,&m,&x,&y,&a,&b);
	P pos[4];
	pos[0]=P(1,1);
	pos[1]=P(n,1);
	pos[2]=P(1,m);
	pos[3]=P(n,m);
	int ans=0x3f3f3f3f;
	for(int i=0;i<4;i++)
	{
		int x1=pos[i].fst;
		int y1=pos[i].sec;
		if(x==x1&&y==y1)
		{
			ans=0;
			break;
		}
		if(abs(x-x1)%a!=0||abs(y-y1)%b!=0)
			continue;
		int na=abs(x-x1)/a;
		int nb=abs(y-y1)/b;
		if(abs(na-nb)%2!=0)
			continue;
		if(a>=n||b>=m)
			continue;
		ans=min(abs(na-nb)+min(na,nb),ans);
	}
	if(ans==0x3f3f3f3f)
	{
		puts("Poor Inna and pony!");
	}
	else
	{
		printf("%d\n",ans);
	}
	
}


B.Inna and Nine

题意,看链接,反正就是一个记录状态转移路径的dp,没什么

dp[i]代表到此为止最多几个9

path[i]代表从哪里转移过来的,只有3种可能

1是从前一个 2是从前前一个 3是两种都可以

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
#define ll unsigned long long 
char s[200000];
ll dp[200000];// 0 left 1 not
ll count1[200000];
ll path[200000];
int main()
{
	scanf("%s",s+1);
	s[0]='0';
	ll n=strlen(s)-1;
	ll m=0;
	if(s[1]=='9')
	{
		dp[1]=1;
	}
	for(ll i=2;i<=n;i++)
	{
		dp[i]=dp[i-1];
		path[i]|=1;
		if(s[i]=='9')
		{
			dp[i]=max(dp[i-1]+1,dp[i]);
		}
		if(s[i]-'0'+s[i-1]-'0'==9)
		{
			if(dp[i]==dp[i-2]+1)
			{
				path[i]|=2;
			}
			if(dp[i]<dp[i-2]+1)
			{
				path[i]=2;
				dp[i]=dp[i-2]+1;
			}
		}
	}
	count1[0]=1;
	count1[1]=1;
	for(ll i=2;i<=n;i++)
	{
		if(path[i]&1)
		{
			count1[i]+=count1[i-1];
		}	
		if(path[i]&2)
		{
			count1[i]+=count1[i-2];
		}
	}
	if(count1[n])
		cout<<count1[n]<<endl;
	else
		cout<<1<<endl;
}

不过CF第二题放DP还是齐葩,没得说。

第二题挂了一个半小时...其他题明天再做把



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 887是一个程序设计竞赛活动,由Codeforces组织举办。根据引用中的代码,该竞赛的题目要求解决一个序列操作的问题。给定一个长度为n的序列,通过执行一系列操作,使得序列变得非sorted,即非严格递增。具体操作是将序列中[1, i]范围内的数字全部加一,同时将[i+1, n]范围内的数字全部减一。问题要求求解最少需要执行多少次操作才能达到要求。 引用中的代码给出了解决这个问题的实现。代码首先读入序列的长度n和序列a。然后通过判断序列是否已经是非sorted,如果是则直接输出0。接下来,代码遍历序列,求出相邻两个数字的差的最小值。最后,计算出最少需要执行的操作次数,并输出结果。 需要注意的是,引用中的代码只是给出了解决问题的一种实现方式,并不代表Codeforces Round 887的具体题目和解答。要了解该竞赛的具体信息,需要参考Codeforces官方网站或相关资料。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Codeforces Round 887 (Div. 2)](https://blog.csdn.net/qq_36545889/article/details/131905067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值