Codeforces Round #220 (Div. 2)

u010660276發表於2013-12-19

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;
}



相關文章