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
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值