Function1

Problem:F

Time Limit:1000ms

Memory Limit:65535K

Description

You know that huicpc0838 has been reviewing his textbooks and doing related exercises for the coming PG exams these days. One day, when he was abused by the sixth chapter of the textbook  Computer Organization Principles, he came up with an idea. He wrote down something in his draft and happily went lunch (at 11:00 am).
Here is what he wrote: int function(int a,int b){
int c=(a&b),d=(a^b);
return c==0? d:function1(c<<1,d);
}
This function will terminated finally without doubt.
I will test it this code tonight after I back to dorm. Do you want to find what's in his mind? Given a,b, can you output the results?

Input

The input will end with EOF, consisting of several blocks. Every block is two lines, every line represents a non-negative integer, whose length is no more that 3000.

Output

Output function1(a,b)%2011.

Sample Input

0
1
31415926535897932384626
2718281828

Sample Output

1
507

题解1:将公式转换一下发现就是求A+B对2011取余,高精度加法模板题。
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
int i,j,k=,n,m,t,x;
long long flag;
char c[],d[],ans[];
while(cin>>c>>d)
{
n=strlen(c);
m=strlen(d);
if (n>m)
{
x=n-m;
for (i=n-;i>=x;i--)
d[i]=d[i-x];
for (i=;i<x;i++)
d[i]='';
}
else
{
x=m-n;
n=m;
for (i=m-;i>=x;i--)
c[i]=c[i-x];
for (i=;i<x;i++)
c[i]='';
}
int jinwei=;
for (i=n-;i>=;i--)
{
ans[i]=((c[i]-'')+(d[i]-'')+jinwei)%+'';
if (c[i]+d[i]-''-''+jinwei>=)
jinwei=;
else
jinwei=;
}
ans[n]='\0';
if(jinwei)
flag=;
else
flag=;
for(i=;i<n;i++)
flag=(flag*+ans[i]-''+)%;
cout<<flag<<endl;
}
return ;
}

题解2:先取余再加,最优解。

#include <iostream>
#include <string.h>
using namespace std;
#define mod 2011
typedef long long ll;
int main()
{
int i;
ll a,b;
char c[],d[];
while(cin>>c>>d)
{
int len1=strlen(c);
int len2=strlen(d);
a=c[]-'';
b=d[]-'';
for(i=;i<len1;i++)
a=(a*+c[i]-'')%mod;
for(i=;i<len2;i++)
b=(b*+d[i]-'')%mod;
cout<<(a+b)%mod<<endl;
}
return ;
}

NEFU 2016省赛演练一 F题 (高精度加法)的更多相关文章

  1. NEFU 2016省赛演练一 I题 (模拟题)

    这题没名字 Problem:I Time Limit:2000ms Memory Limit:65535K Description Now give you an interger m and a s ...

  2. NEFU 2016省赛演练一 B题(递推)

    HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...

  3. (翻译)2016美国数学建模MCM F题(政策)翻译:难民移民政策建模

    PROBLEM F:Modeling Refugee Immigration Policies With hundreds of thousands of refugees moving across ...

  4. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

  5. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  6. HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4818 深深地补一个坑~~~ 现场赛坑在这题了,TAT.... 今天把代码改了下,过掉了,TAT 很明显 ...

  7. (翻译)2016美国数学建模MCM E题(环境)翻译:我们朝向一个干旱的星球?

    PROBLEM E: Are we heading towards a thirsty planet? Will the world run out of clean water? According ...

  8. 经典算法题每日演练——第十七题 Dijkstra算法

    原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...

  9. 经典算法题每日演练——第十一题 Bitmap算法

    原文:经典算法题每日演练--第十一题 Bitmap算法 在所有具有性能优化的数据结构中,我想大家使用最多的就是hash表,是的,在具有定位查找上具有O(1)的常量时间,多么的简洁优美, 但是在特定的场 ...

随机推荐

  1. 【BZOJ-1452】Count 树状数组 套 树状数组

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1769  Solved: 1059[Submit][Stat ...

  2. codevs1064 虫食算

    题目描述 Description 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单的例子: 43#9865#045    +    8468#6 ...

  3. poj 1442 名次树

    这回要求的是第k小的元素, 参考了ljl大神的模板,orz //insert 插入 //remove 删除 //_find 查找 //kth 返回root为根的树中第k小的元素 //treap插入.删 ...

  4. 洛谷P1755 斐波那契的拆分

    题目背景 无 题目描述 已知任意一个正整数都可以拆分为若干个斐波纳契数,现在,让你求出n的拆分方法 输入输出格式 输入格式: 一个数t,表示有t组数据 接下来t行,每行一个数n(如题) 输出格式: t ...

  5. NOIP 2012 T5 借教室 [洛谷P1083]

    题目描述 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要 向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自 ...

  6. Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm

    目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...

  7. Redis操作+python

    自动化接口测试中需要向redis中插入测试数据: 1. 连接redis: import redisself.r = redis.StrictRedis(host=env.REDIS_HOST, por ...

  8. Mac OS X 10.9 Mavericks安装后,Xcode调试时模拟器黑屏的处理方法

    请耐心的等下去吧,少年! 装了Mac OS X 10.9 Mavericks的同学,如果碰到Xcode调试App时,模拟器黑屏(重置也无效),请耐心的等下去吧,大约10来分钟左右黑屏就会消失,App启 ...

  9. SCU 4424(求子集排列数)

    A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice ...

  10. udf提权方法和出现问题汇总

    一.适用条件 1.目标系统是Windows(Win2000,XP,Win2003): 2.你已经拥有MYSQL的某个用户账号,此账号必须有对mysql的insert和delete权限以创建和抛弃函数( ...