Codeforces Round #220 (Div. 2)

来源:互联网 发布:分时博弈指标源码 编辑:程序博客网 时间:2024/05/22 00:49

A:最近脑子非常不好使。。。如果可以的话则商的差一定是偶数

下面是代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int INF = 0x7fffffff;int n,m,i,j,a,b;int Abs(int x){    return x>=0?x:-x;}int solve(int x,int y){    if(x == i && y == j) return 0;    if(x <= a && x + a > n) return INF;    if(y <= b && y + b > m) return INF;    int lx = Abs(i-x), ly = Abs(j-y);    if(lx%a == 0 && ly%b == 0 && Abs(lx/a-ly/b)%2 == 0)        return max(lx/a,ly/b);    return INF;}int main(){    cin >> n >> m >> i >> j >> a >> b;    int ans = INF;    ans = min(ans,solve(1,m));    ans = min(ans,solve(1,1));    ans = min(ans,solve(n,m));    ans = min(ans,solve(n,1));    if(ans == INF)puts("Poor Inna and pony!");    else cout << ans << endl;    return 0;}

B:给一个数相邻两个数如果和为9的话,则便成9,问这个数含最多的9的变化方法。

下面是代码:

#include <cmath>#include <string>#include <cstdio>#include <cstring>#include <algorithm>#include<iostream>using namespace std;const int maxn = 100005;char a[maxn];int main(){    long long res;    while (scanf("%s",a)!=EOF){        int len = strlen(a);        res = 1;        for (int i=0; i<len; i++){           long long tmp = 1;           while (i<len-1 && a[i]+a[i+1] - '0' - '0' == 9){                tmp += 1;                i++;                cout<<tmp<<endl;           }           if (tmp % 2 == 1){               res *= tmp/2 + 1;           }        }        printf("%I64d\n",res);    }    return 0;}



0 0
原创粉丝点击