http://codeforces.com/contest/318
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
题意: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;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
题意:初始左边原点有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;
}