Codeforces Round #220 (Div. 2)
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;
}
相關文章
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round 945 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 967 (Div. 2)