构造 D - Finals in arithmetic ★ ★

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 100100
#define MOD 1000000007

char str[maxn];
char ans[maxn];
int s[maxn];
int n;
int judge()
{
for(int i = 0; i < n / 2; )
{
int l = i,r = n - 1 - i;
if(s[l] == s[r])
i++;
else if(s[l] == s[r] + 1 || s[l] == s[r]+11)
{
s[l]--;
s[l+1] += 10;
}
else if(s[l] == s[r] + 10)
{
s[r] += 10;
s[r-1]--;
}
else
return 0;
}
if(n & 1)
{
if(s[n/2] & 1 || s[n/2] > 18 || s[n/2] < 0)
return 0;
ans[n/2] = s[n/2] / 2 + '0';
}
for(int i = 0; i < n / 2; i++)
{
if(s[i] > 18 || s[i] < 0)
return 0;
ans[i] = (s[i] + 1) / 2 + '0';
ans[n-i-1] = s[i] / 2 + '0';
}
return ans[0] > '0';
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,C = 1;
//scanf("%d",&t);
while(scanf("%s",str) != EOF)
{
n = strlen(str);
for(int i = 0; i < n; i++)
s[i] = str[i] - '0';
if(judge())
printf("%s\n",ans);
else if(str[0] == '1' && n > 1)
{
for(int i = 0; i < n; i++)
s[i] = str[i+1] - '0';
s[0] += 10;
n--;
if(judge())
printf("%s\n",ans);
else
printf("0\n");
}
else
printf("0\n");
}
return 0;
}

cf#342-D - Finals in arithmetic-构造

2016-02-15 15:50:10

Codeforces #342 D. Finals in arithmetic 模拟 构造

2016-02-09 21:10:52

Codeforces 625D ---- Finals in arithmetic

2016-02-14 09:14:20

Codeforces 629 D Finals in arithmetic(最大上升子序列和，O(nlogn)、线段树/树状数组)

2016-07-25 10:52:21

Finals in arithmetic CodeForces - 625D （构造）

2018-03-30 10:30:24

Codeforces 625 D Finals in arithmetic

2016-02-08 12:43:53

Codeforces 625D Finals in arithmetic(构造)

2016-05-31 16:41:55

D. Almost Arithmetic Progression

2018-05-14 16:37:05

codeforces 625-D. Finals in arithmetic（构造+模拟）

2017-07-16 19:03:28

Codeforces Round #224 (Div. 2) C. Arithmetic Progression【构造等差数列】

2016-11-27 01:17:47