https://codeforces.com/contest/1181/problem/B

从中间拆开然后用大数搞一波。

当时没想清楚奇偶是怎么弄,其实都可以,奇数长度字符串的中心就在len/2,偶数长度字符串的中心恰好是len/2和len/2-1。

但是要是作为末尾指针的位置来说的话

奇数长度字符串:把中心分给后半串,那么分割点是len/2。把中心分给前半串,那么分割点是len/2+1。

偶数长度字符串:分割点是len/2。

注意子串的取法,其实最方便的还是传头尾指针进去。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; inline int read() {
int x=0;
int f=0;
char c;
do {
c=getchar();
if(c=='-')
f=1;
} while(c<'0'||c>'9');
do {
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
} while(c>='0'&&c<='9');
return f?-x:x;
} inline void _write(int x) {
if(x>9)
_write(x/10);
putchar(x%10+'0');
} inline void write(int x) {
if(x<0) {
putchar('-');
x=-x;
}
_write(x);
putchar('\n');
} struct BigInt {
const static int mod=10000;
const static int DLEN=4;
int a[30005],len; BigInt() {
memset(a,0,sizeof(a));
len=1;
} BigInt(int v) {
memset(a,0,sizeof(a));
len=0;
do {
a[len++]=v%mod;
v/=mod;
} while(v);
} BigInt(const char *s) {
memset(a,0,sizeof(a));
int L=strlen(s);
len = L/DLEN;
if(L%DLEN)
len++;
int index=0;
for(int i=L-1; i>=0; i-=DLEN) {
int t=0;
int k=i-DLEN+1;
if(k<0)
k=0;
for(int j=k; j<=i; j++)
t=t*10+s[j]-'0';
a[index++] = t;
}
} BigInt operator+(const BigInt &b)const {
BigInt res;
res.len=max(len,b.len);
for(int i=0; i<res.len; i++) {
res.a[i]+=((i<len)?a[i]:0)+((i<b.len)?b.a[i]:0);
res.a[i+1]+=res.a[i]/mod;
res.a[i]%=mod;
}
if(res.a[res.len] > 0)
res.len++;
return res;
} BigInt operator*(const BigInt &b)const {
BigInt res;
for(int i=0; i<len; i++) {
int up = 0;
for(int j=0; j<b.len; j++) {
int temp=a[i]*b.a[j]+res.a[i+j]+up;
res.a[i+j]=temp%mod;
up=temp/mod;
}
if(up != 0)
res.a[i+ b.len]=up;
}
res.len=len+b.len;
while(res.a[res.len-1]==0&&res.len>1)
res.len--;
return res;
} bool operator>(const BigInt &b)const {
if(len>b.len)
return true;
else if(len==b.len) {
int ln=len-1;
while(a[ln]==b.a[ln]&&ln>=0)
ln--;
if(ln>=0&&a[ln]>b.a[ln])
return true;
else
return false;
} else
return false;
} void output() {
printf("%d",a[len-1]);
for(int i = len-2; i >=0 ; i--)
printf("%04d",a[i]);
printf("\n");
}
}; char s[100005];
char t[100005]; int main() {
#ifdef Yinku
freopen("Yinku.in","r",stdin);
//freopen("Yinku.out","w",stdout);
#endif // Yinku
int l;
scanf("%d%s",&l,s);
int m1=l/2;
int m2=l/2+1;
int h1=m1;
while(s[h1]=='0')
h1--;
int h2=m2;
while(h2<l&&s[h2]=='0')
h2++;
strncpy(t,s,h1);
t[h1]='\0';
BigInt a(t);
strcpy(t,s+h1);
BigInt b(t);
BigInt c=a+b; strncpy(t,s,h2);
t[h2]='\0';
a=BigInt(t);
strcpy(t,s+h2);
b=BigInt(t);
BigInt c2=a+b;
if(c>c2)
c2.output();
else
c.output();
}

Codeforces - 1181B - Split a Number - 贪心的更多相关文章

  1. Codeforces C. Split a Number(贪心大数运算)

    题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...

  2. Codeforces Round #567 (Div. 2)B. Split a Number (字符串,贪心)

    B. Split a Number time limit per test2 seconds memory limit per test512 megabytes inputstandard inpu ...

  3. Codeforces Round #567 (Div. 2) B. Split a Number

    Split a Number time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  4. Split the Number(思维)

    You are given an integer x. Your task is to split the number x into exactly n strictly positive inte ...

  5. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  6. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  7. B. Split a Number(字符串加法)

    Dima worked all day and wrote down on a long paper strip his favorite number nn consisting of ll dig ...

  8. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  9. Codeforces 980 E. The Number Games

    \(>Codeforces \space 980 E. The Number Games<\) 题目大意 : 有一棵点数为 \(n\) 的数,第 \(i\) 个点的点权是 \(2^i\) ...

随机推荐

  1. JavaScript中call、apply个人理解

    JavaScript中call.apply个人理解 一句话即通俗的说:call.apply 是为了改变this的状态而存在的 }; } function personInfo(name,age){ t ...

  2. java:eclipse安装tomcat插件及配置tomcat

    我们都知道myeclipse自带tomat图标,而eclipse却没有,若想eclipse实现带有tomcat图标可以下载tomcat插件 tomcat插件下载地址:http://www.eclips ...

  3. hash算法打散存储文件

    1.首先,为防止一个目录下面出现太多文件,所以使用hash算法打散存储 举例代码: int hashcode = filename.hashCode();//得到hashCode int dir1 = ...

  4. 前端多媒体(7)—— 在浏览器中实现rtmp推流

    示例:https://young-cowboy.github.io/gallery/rtmp_client/index.html 在国内的直播场景中通常使用,rtmp协议作为推流协议.RTMP是Rea ...

  5. 设计模式 之 《观察者模式 (Observer)》

    #ifndef __OBSERVER_MODEL__ #define __OBSERVER_MODEL__ #include <string> #include <iostream& ...

  6. swiper轮播 swiper整屏轮播

    近期坐了几个移动端 整屏轮播的  效果 之前都是自己一个个写,之前听说过swiper插件,没有使用过,今天一尝试,果然,爽 使用方法示例 <div class="swiper-cont ...

  7. [BZOJ1396&2865]识别子串

    bzoj1396 bzoj2865 dbzoj1396 dbzoj2865 题面 XX在进行字符串研究的时候,遇到了一个十分棘手的问题. 在这个问题中,给定一个字符串\(S\),与一个整数\(K\), ...

  8. 不同类型input尺寸设置区别

    最近发现为不用类型的input设置相同的尺寸,却得到了不一样的尺寸结果.发现不同类型的input的height和width竟然含义不同.在此小整理一下. (1)button类型 规律 button类型 ...

  9. Git 权限控制

    除了 Git 命令,权限控制也是 Git 中极为重要的组成部分,本文主要介绍 GitLab 系统提供的最常用的权限控制功能. 一.分配成员角色 首先来了解下,Git 中的五种角色: 每一种角色所拥有的 ...

  10. Linux IO实时监控iostat命令详解(转)

    简介 iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的次数和时间 ...