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. 机器学习(二十四)— 偏差Bias 与方差Variance

    1.首先 Error = Bias + Variance  Error反映的是整个模型的准确度, Bias反映的是模型在样本上的输出与真实值之间的误差,即模型本身的精准度, Variance反映的是模 ...

  2. 一个用 vue 写的树层级组件 vue-ztree

    最近看了大神的关于vue-ztree的博客,感觉很赞,于是摘抄下来,方便自己学习,机智girl,哈哈哈O(∩_∩)O 最近由于后台管理项目的需要,页面需要制作一个无限树的需求,我第一感就想到了插件 z ...

  3. Javascript-- jQuery事件篇(3)

    on()的多事件绑定 之前学的鼠标事件,表单事件与键盘事件都有个特点,就是直接给元素绑定一个处理函数,所有这类事件都是属于快捷处理.翻开源码其实可以看到,所有的快捷事件在底层的处理都是通过一个&quo ...

  4. Java 关于创建String对象过程的内存分配

    一.String s = "abc"  和 String s = new String("abc") 的区别 1.String s = "abc&qu ...

  5. bzoj 4199: [Noi2015]品酒大会 后缀树

    题目大意: 给定一个长为n的字符串,每个下标有一个权\(w_i\),定义下标\(i,j\)是r相似的仅当\(r \leq LCP(suf(i),suf(j))\)且这个相似的权为\(w_i,w_j\) ...

  6. Unity3d中SendMessage 用法

      Message相关有3条指令:SendMessage ("函数名",参数,SendMessageOptions) //GameObject自身的ScriptBroadcastM ...

  7. XMPP群聊消息重复,自己收到自己发出的消息,群警告消息如何屏蔽

    在XMPP的"groupchat"中,创建群的时候会收到群发的"This room is locked from entry until configuration is ...

  8. 经过一年时间的沉淀 再次回首 TCP Socket服务器编程 (二)

    ------------------ 前言 ------------------ 发了第一篇文章后,有不少同志留言,看来socket编程仍然是软件系统里面一个比较难的部分. 第一篇文章主要介绍了传输协 ...

  9. 简单的RBAC用户角色权限控制

    Java web项目中,无论项目是大是小,或多或少都会涉及到用户访问权限的控制,权限管理总体的设计思路就是,不该看的不看,不该做的不做!据我目前的了解,我所知道的几种实现访问权限控制的方式有: JQu ...

  10. openstack常见问题汇总

    汇总下常见的问题以及解释下一些比较容易让人萌的参数配置等等 问题汇总1.使用纯文本模式进行复制粘贴,打死不要用word!!!可以解决绝大多数问题,如果你依然执迷不悟,那么就好自为之吧 2.创建路由器时 ...