刚刚讲完数论,善良的学长就为我们举办了一次紧张刺激的考(zuo)试(ti)。
A题
- A Simple Problem with Integers

Description
给出了一个序列,你需要处理如下两种询问。
“C a b c”表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 10000)。
“Q a b” 询问[a, b]区间中所有值的和。

Input
第一行包含两个整数N, Q。1 ≤ N,Q ≤ 100000.
第二行包含n个整数,表示初始的序列A (-1000000000 ≤ Ai ≤ 1000000000)。
接下来Q行询问,格式如题目描述。

Output
对于每一个Q开头的询问,你需要输出相应的答案,每个答案一行。

Sample Input
10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4

Sample Output
4
55
9
15

鉴于刚刚学完线段树,A题就出了一道线段树裸题来复习……

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int SZ = 2000000;struct sgt
{int l, r;LL sum, add;
}tree[SZ];
int num[SZ];
char op[5];void update(int now)
{tree[now].sum = tree[now << 1].sum + tree[now << 1 | 1].sum;
}void build(int now, int l, int r)
{tree[now].l = l;tree[now].r = r;if(l == r){tree[now].sum = num[l];return ;}int mid = (l + r) >> 1;build(now << 1, l, mid);build(now << 1 | 1, mid + 1, r);update(now);
}void pushdown(int now)
{if(tree[now].add != 0){tree[now << 1].sum += (tree[now << 1].r - tree[now << 1].l + 1) * tree[now].add;tree[now << 1].add += tree[now].add;tree[now << 1 | 1].sum += (tree[now << 1 | 1].r - tree[now << 1 | 1].l + 1) * tree[now].add;tree[now << 1 | 1].add += tree[now].add;tree[now].add = 0;update(now);}
}void change(int now, int l, int  r, int value)
{if(l <= tree[now].l && tree[now].r <= r){tree[now].sum += (tree[now].r - tree[now].l + 1) * value;tree[now].add += value;return ;}pushdown(now);int mid = (tree[now].l + tree[now].r) >> 1;if(l <= mid)change(now << 1, l, r, value);if(r > mid)change(now << 1 | 1, l, r, value);update(now);
}LL ask(int now, int l, int r)
{if(l <= tree[now].l && tree[now].r <= r)return tree[now].sum;pushdown(now);LL ans = 0;int mid = (tree[now].l + tree[now].r) >> 1;if(l <= mid)ans += ask(now << 1, l, r);if(r > mid)ans += ask(now << 1 | 1, l, r);return ans;
}int main()
{int n, q;scanf("%d%d", &n, &q);for(int i = 1;i <= n; i ++)scanf("%d", &num[i]);build(1, 1, n);while(q --){int l, r, value;scanf("%s", op);if(op[0] == 'Q'){scanf("%d%d", &l, &r);printf("%lld\n", ask(1, l, r));}if(op[0] == 'C'){scanf("%d%d%d", &l, &r, &value);change(1, l, r, value);}} return 0;
}

B题
- Fibonacci

Description
In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
An alternative formula for the Fibonacci sequence is

Given an integer n, your goal is to compute the last 4 digits of Fn.

Input
The input test file will contain multiple test cases. Each test case
consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000).
The end-of-file is denoted by a single line containing the number −1.

Output
For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).

Sample Input
0
9
999999999
1000000000
-1

Sample Output
0
34
626
6875

Hint
As a reminder, matrix multiplication is associative, and the product of two 2 × 2 matrices is given by

Also, note that raising any 2 × 2 matrix to the 0th power gives the identity matrix:

如学长们所说,这个题的答案就写在题面上……
矩阵 + 快速幂求斐波那契数列……

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
const int k = 10000;struct mat
{LL a[3][3];
};
mat operator *(mat a, mat b)
{mat c;for(int i = 1; i <= 2; i++)for(int j = 1; j <= 2; j++)c.a[i][j] = ((a.a[i][1] * b.a[1][j]) % k + (a.a[i][2] * b.a[2][j]) % k) % k;return c;
}
mat s;mat ksm(mat x,int y)
{if(y == 1)return x;mat a = ksm(x, y/2);if(y % 2)return a * a * s;elsereturn a * a;
}int main()
{s.a[1][1] = 1;s.a[1][2] = 1;s.a[2][1] = 1;s.a[2][2] = 0;int n;mat q;q.a[1][1] = 1;q.a[1][2] = 0;q.a[2][1] = 0;q.a[2][2] = 0;scanf("%d", &n);while(n != -1){if(n == 0)printf("0\n");if(n == 1|| n == 2)printf("1\n");if(n > 2){mat ans = q * ksm(s, n-1);printf("%d\n", ans.a[1][1]);}scanf("%d", &n);}
}

C题
- 青蛙的约会

Description
两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。
我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。纬度线总长L米。现在要你求出它们跳了几次以后才会碰面。

Input
输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。

Output
输出碰面所需要的跳跃次数,如果永远不可能碰面则输出一行”Impossible”

Sample Input
1 2 3 4 5

Sample Output
4

拓展欧几里得求解……

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
LL x, y, m, n, l;LL exgcd(LL a, LL b, LL &x, LL &y)
{if(b == 0){x = 1; y = 0;return a;}LL t = exgcd(b, a % b, x, y);LL xx = x;x = y;y = xx - a / b * y;return t;
}int main()
{scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &l);if(m == n)printf("Impossible");else{if(m < n)   swap(m, n), swap(x, y);LL a, k;LL c = y - x;LL d = exgcd(m-n, l, a, k);if(c % d)printf("Impossible");else{LL ans = (((a * c / d) % (l / d) + (l /d)) % (l /d));printf("%lld", ans);}}return 0;
}

D题
-Help is needed for Dexter

Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not have time to spend on this silly task, so he wants your help.
There will be a button, when it will be pushed a random number N will be chosen by computer.Then on screen there will be numbers from 1 to N. Dee Dee can choose any number of numbers from the numbers on the screen, and then she will command computer to subtract a positive number chosen by her (not necessarily on screen) from the selected numbers. Her objective will be to make all the numbers 0.
For example if N = 3, then on screen there will be 3 numbers on screen: 1, 2, 3. Say she now selects 1 and 2. Commands to subtract 1, then the numbers on the screen will be: 0, 1, 3. Then she selects 1 and 3 and commands to subtract 1. Now the numbers are 0, 0, 2. Now she subtracts 2 from 2 and all the numbers become 0.
Dexter is not so dumb to understand that this can be done very easily, so to make a twist he will give a limit L for each N and surely L will be as minimum as possible so that it is still possible to win
within L moves. But Dexter does not have time to think how to determine L for each N, so he asks you to write a code which will take N as input and give L as output.

Input
Input consists of several lines each with N such that 1 ≤ N ≤ 1, 000,000, 000. Input will be terminated by end of file

Output
For each N output L in separate lines.

Sample Input
1
2
3

Sample Output
1
2
2

题目的大体意思是给定数 1 - n,每次选择一个区间减去同一个数,不能小于0。最后输出n行,第i行表示把i变为0的最少操作数。
一个找规律的题……

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;LL ask(LL n)
{return (n == 1) ? 1 : ask(n / 2) + 1;
}int main()
{LL n, haha = 0;while(scanf("%lld", &n) != EOF){printf("%lld\n", ask(n));}return 0;
}

E题
- 水题

Description
监狱有连续编号为1…N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱

Input
输入两个整数M,N.1<=M<=10^8,1<=N<=10^12

Output
可能越狱的状态数,模100003取余

Sample Input
2 3

Sample Output
6

Hint
6种状态为(000)(001)(011)(100)(110)(111)

要推公式,好麻烦的……看代码就可以明白吧……

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;LL ksm(LL m, LL n)
{if(m == 1)  return 1;if(m == 0)  return 0;if(n == 0)  return 1;if(n == 1)  return m;LL haha = ksm(m, n / 2);if(n % 2 == 0)return ((haha % 100003) * (haha % 100003)) % 100003;elsereturn ((haha % 100003) * (haha % 100003) * (m % 100003)) % 100003;
}int main()
{LL n, m;scanf("%lld%lld", &m, &n);LL tot = ksm(m, n);LL haha = ((m % 100003) * (ksm(m- 1, n -1) % 100003)) % 100003;LL ans;if(tot < haha)ans = ((tot + 100003) - haha) % 100003;elseans = ((tot % 100003) - (haha % 100003)) % 100003;printf("%lld", ans);return 0;
}

嗯,这样愉快的math test 就结束了……题目难度还可以吧……愉快的拿到了rank 1……

转载于:https://www.cnblogs.com/Loi-Vampire/p/6017055.html

Vjudge 2016-5-10 math test相关推荐

  1. 2016年10月起微软更改了更新服务模型

    https://blogs.technet.microsoft.com/windowsitpro/2016/08/15/further-simplifying-servicing-model-for- ...

  2. 2016年10月计算机网络技术,2016年10月自考《计算机网络技术》练习题及答案1

    2016年10月自考备考开始了,为了帮助自考生在考试阶段顺利复习,猎学网小编为你提供2016年10月自考<计算机网络技术>练习题及答案1,检测备考情况,从而进行查缺补漏.更多2016自学考 ...

  3. 2016年10月计算机网络技术,2016年10月自考计算机网络技术练习题及答案(2)

    2016年10月自考计算机网络技术练习题及答案(2) 一.判断题(针对下面的描述,对的打'√',错的打'X') 1.网络互联层的协议不包括ICMP协议.(错误) 2.在同一个网络中,一个主机可有多个I ...

  4. 计算机技能测试题6,2016年10月自考计算机网络技术练习题及答案(6)

    [正保网校课程]为了使各位考生能顺利通过2016年自学考试,无忧考网为大家特别推荐2016年自学考试课程!点击进入免费试听<<<< 11.对一个网络进行层次结构的划分时应做到: ...

  5. 考虑单用户计算机上的下列I O操作,操作系统概论自考2016年10月真题

    操作系统概论自考2016年10月真题及答案解析 本试卷为单选题型,多选,填空题,简答题,综合等题型. 一.单项选择题在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内.错 ...

  6. DB-Engines:2016年10月份全球数据库排名

    2016年10月份全球数据库排名 2016-10-31 技术最前线 (点击上方公众号,可快速关注) 编译:开源中国 链接:www.oschina.net/news/78569/db-engines-r ...

  7. 2016年10月9日 星期日 --出埃及记 Exodus 18:20

    2016年10月9日 星期日 --出埃及记 Exodus 18:20 Teach them the decrees and laws, and show them the way to live an ...

  8. TP-Link WR340G+ 路由器桥接实践(2016年10月更新tplink新产品wifi中继器设备)

    TP-Link WR340G+ 路由器桥接实践 Uncle家买了TCL互联网电视放在客厅,adsl原先放在书房,距离有15米左右,原来没有布网线,现在也不希望布明线.TCL上只有一个网线口,不像长虹有 ...

  9. 2016年10月13日 星期四 --出埃及记 Exodus 18:24

    2016年10月13日 星期四 --出埃及记 Exodus 18:24 Moses listened to his father-in-law and did everything he said. ...

  10. 00018计算机应用基础真题及答案,全国自考2016年10月00018计算机应用基础历年试题(含答案)...

    全国2016年10月高等教育自学考试 计算机应用基础 代码:00018 一.单项选择题 1.微型计算机属于 A.第1代计算机 B.第2代计算机 C.第3代计算机 D.第4代计算机 2.在以下打印机中, ...

最新文章

  1. Sciences:Knight组发表尸体降解过程中的微生物组
  2. Delphi中PCAHR的妙用
  3. PM2.5检测 -- PMS7003 串口测试
  4. 华为模拟器-三次交换机、链路捆绑、单臂路由综合实验
  5. 减肥瘦不下来的原因找到了
  6. 需要的依赖_三十而已:夫妻关系中需要的是坦诚和依赖
  7. python两层装饰器_python装饰器
  8. 通过常用监控命令快速发现性能问题
  9. 你第1个100万怎么赚的?
  10. Java基础篇:简单数据类型
  11. 可执行文件的 MD5 碰撞
  12. android系统 限制应用安装程序,安卓手机不能安装软件是什么原因 安卓手机不能安装软件解决方法...
  13. ubuntu 安装pyqt IDE使用eric 辛酸史
  14. 安装Adobe Reader 时报错:HRESULT:0x80070422
  15. intouch负值显示0_InTouch常见问题
  16. word文档的尺寸和字号对照表
  17. 预充电电路工作原理_电动汽车电控系统预充电原理
  18. 荣耀play的android版本,荣耀Play3搭载了哪个版本系统 聪明的系统更懂你
  19. 【转】区块链经济学:制度加密经济学入门指南
  20. 基于Java的网上作业批改系统

热门文章

  1. activiti报错ProcessEngines.getDefaultProcessEngine()为null
  2. Chapter 1 Securing Your Server and Network(6):为SQL Server访问配置防火墙
  3. 用lsof恢复已删除的文件
  4. nginx解析漏洞 只要可以上传文件就会被黑
  5. IEEE 1588-2002 Precision Time Protocol(PTP)
  6. 利用关系图表深度挖掘潜在决策影响关系——微软CRM炫酷介绍之四
  7. JavaScript常用工具Date对象和Math介绍介绍
  8. Python进制转换(利用栈)
  9. Python文件读写模式
  10. java怎么在哪写代码_java把这段代码不写死问题出现在哪儿