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. 【bzoj3150】 cqoi2013—新Nim游戏

    www.lydsy.com/JudgeOnline/problem.php?id=3105 (题目链接) 题意 在第一个回合中,第一个游戏者可以直接拿走若干个整堆的火柴.可以一堆都不拿,但不可以全部拿 ...

  2. 【poj1090】 Chain

    http://poj.org/problem?id=1090 (题目链接) 题意 给出九连环的初始状态,要求将环全部取下需要走多少步. Solution 格雷码:神犇博客 当然递推也可以做. 代码 / ...

  3. Linux Rootkit Sample && Rootkit Defenser Analysis

    目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...

  4. window自动切换ip的脚本

    因为总要切换ip,所以百度了一下脚本 如下http://jingyan.baidu.com/article/d2b1d1029d21b95c7e37d4fa.html 动态ip netsh inter ...

  5. 查看apk包名package和入口activity名称的方法

    ctrl+r 打开CMD窗口 进入sdk-aapt目录 执行命令:aapt dump badging xx.apk 内容太多?不好看,没关系,全部拷出来,ctrl+f,so easy! package ...

  6. ecshop后台导航修改教程说明

    ecshop后台导航修改教程说明 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2014-06-25   需要操作的文件为: 1.修改admin\includes\in ...

  7. Eclipse下搭建Hadoop2.4.0开发环境

    一.安装Eclipse 下载Eclipse,解压安装,例如安装到/usr/local,即/usr/local/eclipse 4.3.1版本下载地址:http://pan.baidu.com/s/1e ...

  8. IOS学习笔记—苹果推送机制APNs

    转自:唐韧_Ryan http://blog.csdn.net/ryantang03/article/details/8482259 推送是解决轮询所造成的流量消耗和 电量消耗的一个比较好的解决方案, ...

  9. mysql 查看 删除 日志操作总结(包括单独和主从mysql)

    我们可以在mysql的安装目录下看到mysql的二进制日志文件,如mysql-bin.000***等,很多人都不及时的处理,导致整个硬盘被塞满也是有可能的.这些是数据库的操作日志.它记录了我们平时使用 ...

  10. WPF 检测输入状态

    [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); pub ...