Codeforces 1244 A,B,C

A.Pens and Pencils
传送门

签到题

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int t;
double a,b,c,d,k;
 
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&k);
		int x=ceil(a/c);
		int y=k-x;
		if(y>=ceil(b/d))
		{
			printf("%d %d\n",x,y);
		}
		else
		{
			printf("-1\n");
		}
	}
	return 0;
}



B.Rooms and Staircases
传送门

在这里插入图片描述
分别从左往右,和从右往左找第一个‘1’,最佳走法应该是走到‘1’后走到下一层,然后往回走,如图中的 1-2-3-4-4-3-2-1 。取(l-1,n-r) 的最小值,在用 n 减,即是走一层的最长路径.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
 
using namespace std;

int n,t;
char str[1005];

int main()
{
    scanf("%d",&t);
    while(T--)
    {
        scanf("%d%s",&n,str+1);
        int l=-1,r=-1;
        for(int i=1;i<=n;i++)
		{
          if(str[i]=='1')
		  {
			l=i;
			break;
		  }
        }
        for(int i=n;i>=1;i--)
		{
          if(str[i]=='1')
		  {
			r=i;
			break;
    	  }
        }
        if(l==-1 && r==-1)
        	printf("%d\n",n);
        else
        	printf("%d\n",2*(n-min(l-1,n-r)));
    }
    return 0;
}


C.The Football Season
传送门

扩展欧几里得定理,求一元二次方程,只要判断两个最小正整数x0,y0的两种情况下可不可以实现,如果这两种都不能符合,那么其他的也一定无法实现。
最初要判断方程是否有解,中途注意取模,否则会爆。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
ll n,p,w,d;
ll gcd(ll a,ll b)
{
  if(b==0)
  {
    return a;
  }
  return gcd(b,a%b);
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
  if(b==0)
  {
    x=1;
    y=0;
    return a;
  }
  ll r=exgcd(b,a%b,x,y);
  ll t=x;
  x=y;
  y=t-(a/b)*y;
  return r;
}
int main()
{
    scanf("%lld%lld%lld%lld",&n,&p,&w,&d);
    ll x,y;
    ll ans=exgcd(w,d,x,y);
    if(p%ans!=0)
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		ll s=d/ans;
		x=x%s*((p/ans)%s);
        //x=x*p/ans; 这样处理会爆
		ll x0=(x%s+s)%s;
		ll y0=(p-w*x0)/d;
		if(x0+y0<=n&&x0>=0&&y0>=0)
		{
			printf("%lld %lld %lld\n",x0,y0,n-x0-y0);
			return 0;
		}
		ll ss=w/ans;
		y0=(y0%ss+ss)%ss;
		x0=(p-d*y0)/w;
		if(x0+y0<=n&&x0>=0&&y0>=0)
		{
			printf("%lld %lld %lld\n",x0,y0,n-x0-y0);
			return 0;
		}
		printf("-1\n");
	}
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值