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. codeforces 720A:Closing ceremony

    Description The closing ceremony of Squanch Code Cup is held in the big hall with n × m seats, arran ...

  2. 记录一次MVC 3.0错误 HTTP 404您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。

    在部署到IIS7时,MVC3报了一个找不到资源的错误,文件肯定是有的,而且页面是肯定报错的,也就说内部运行错误了,而MVC把错误没有抛出来而已: 所以对症下药,发觉我的项目里面用了rexs进行多语言, ...

  3. C++处理一个动态规划的问题

    嗯哼,别人问的问题,看的我也头晕,百度了一下动态规划,看了看才想起来该怎么做,今天写了写代码,实现了~ 要求是递归,动态规划,想了想这种方法也是最简单的~ 所谓动态规划:把多阶段过程转化为一系列单阶段 ...

  4. ubuntu 12.04安装telnet和ssh服务

    ubuntu安装telnet服务 1. sudo apt-get install xinetd telnetd sudo vi /etc/inetd.conf并加入以下一行,假如没有发现这个文件,自己 ...

  5. Handler.dispatchMessage handleMessage

    "main@3972" prio=5 runnable java.lang.Thread.State: RUNNABLE at com.ease.financialoa.modul ...

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

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

  7. Glut 回调函数小结

    2014-04-08  16:25:50   void glutDisplayFunc(void (*func)(void)); 注册当前窗口的显示回调函数 参数: func:形为void func( ...

  8. Linux下SVN安装配置和使用中遇到的问题

    两个命令: svn info :显示版本库信息,svn的下载url等. svn co https://xxxxx/xxx   wodemulu   (通过我的目录制定co的文件夹) svn st:显示 ...

  9. Redis介绍以及安装(Linux与windows)

    1.liunux系统 redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的 不足,它支持存储的value类型 ...

  10. 一个C++类的注释:

    #ifndef __RUNTIMEPARA__HPP#define __RUNTIMEPARA__HPP #include <string> //后面会有介绍 #include <m ...