codeforces contest 318

http://codeforces.com/contest/318

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

C 317A Perfect Pair

题意:m-perfect的定义是:对于一个pair(x,y),如果其中一个数≥m,那么它就是m-perfect的。

有一种变换,可以把(x,y)变换成(x+y,y)或者(x,x+y)。给出x,y,m,问最小需要几次变换,得到一个m-perfect的pair。

题解:两个数都是负数:肯定会越变换越小,所以直接判断。

(x,y)已经是m-perfect的:直接判断。

x+y肯定要替换min(x,y),这样得到的结果才更优。所以如果其中一个是负数,我们要经过几次变换使得它变成正的。

然后暴力去跑要变换几次就行了。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define de(x) cout << #x << "=" << x << endl
ll mat[93];
void init() {
	mat[1]=1;mat[2]=1;
	for(int i=3;i<=92;++i) {
		mat[i]=mat[i-1]+mat[i-2];
	}
}
int main() {
	init();
	ll x,y,m;
	while(~scanf("%I64d%I64d%I64d",&x,&y,&m)) {
		if(x<=0&&y<=0) {
			if(x>=m||y>=m) puts("0");
			else puts("-1");
			continue;
		}
		if(x>=m||y>=m) {
			puts("0");
			continue;
		}
		if(x>y) swap(x,y);
		ll cnt=0;
		if(x<=0) cnt=-x/y;
		if(cnt*y<-x) cnt++;
		x=x+cnt*y;
		while(x<m&&y<m) {
			if(x<y) x+=y;
			else y+=x;
			++cnt;
		}
		printf("%I64d\n",cnt);
	}
    return 0;
}


//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

D 317B Ants

题意:初始左边原点有n只蚂蚁,它们会向四个方向移动,直到每个点的蚂蚁少于四个。

题解:跑一下极限数据,发现可以暴力。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define de(x) cout << #x << "=" << x << endl
const int N=200;
int a[N][N];
int main() {
    int n,q;
    while(~scanf("%d%d",&n,&q)) {
        a[100][100]=n;
        for(;;) {
            int flag=1;
            for(int i=1;i<N;++i) {
                for(int j=1;j<N;++j) {
                    if(a[i][j]>=4) {
                        a[i-1][j]+=a[i][j]/4;
                        a[i+1][j]+=a[i][j]/4;
                        a[i][j-1]+=a[i][j]/4;
                        a[i][j+1]+=a[i][j]/4;
                        a[i][j]%=4;
                        flag=0;
                    }
                }
            }
            if(flag) break;
        }
        int x,y;
        while(q--) {
            scanf("%d%d",&x,&y);
            x+=100;y+=100;
            if(x<1||x>=N||y<1||y>=N) puts("0");
            else printf("%d\n",a[x][y]);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值