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. easyVS

    easyVS 详细说明点这里

  2. 洛谷P2320 [HNOI2006]鬼谷子的钱袋

    https://www.luogu.org/problem/show?pid=2320#sub 题目描述全是图 数学思维,分治思想 假设总数为n 从n/2+1到n的数都可以用1~n的数+n/2表示出来 ...

  3. Python之MySQL

    本文我们为大家介绍 Python3 使用 PyMySQL 连接数据库,并实现简单的增删改查. 什么是 PyMySQL? PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一 ...

  4. HBase概念学习(十)HBase与MongDB等NoSQL数据库对照

    转载请注明出处: jiq•钦's technical Blog - 季义钦 一.开篇 淘宝之前使用的存储层架构一直是MySQL数据库,配合以MongDB,Tair等存储. MySQL因为开源,而且生态 ...

  5. Android讯飞语音云语音听写学习

    讯飞语音云语音听写学习         这几天两个舍友都买了iPhone 6S,玩起了"Hey, Siri",我依旧对我的Nexus 5喊着"OK,Google" ...

  6. 求任意长度数组的最大值(整数类型)。利用params参数实现任意长度的改变。

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. 解决微信OAuth2.0网页授权回调域名只能设置一个的问题

    https://github.com/HADB/GetWeixinCode GetWeixinCode 解决微信OAuth2.0网页授权回调域名只能设置一个的问题 使用方法 部署get-weixin- ...

  8. Assembly文件被锁定

    使用 Assembly.LoadFile 加载程序集后 ,被加载的文件就会被锁定,之后就不能对其执行转移.删除等操作 为了解决次问题,我们可以先读取成字节流,然后转换成Assembly.代码如下:复制 ...

  9. 下载安装resin-3.X服务器并配置到myeclipse

    前提是先安装jdk,具体自己安装. 1.到resin官网http://www.caucho.com/download/下载相应压缩包,比如resin-3.2.0.zip 2.解压下载的resin-3. ...

  10. C++中析构函数的作用,

    如果构造函数打开了一个文件,最后不需要使用时文件就要被关闭.析构函数允许类自动完成类似清理工作,不必调用其他成员函数.析构函数也是特殊的类成员函数.简单来说,析构函数与构造函数的作用正好相反,它用来完 ...