【数学】【模拟】XMU 1044 伪伪随机数产生器
题目链接:
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1044
题目大意:
求首项为0,公比为x的等差数列组成的数字条的第y位数字是几。(x,y<=2*109)
题目思路:
【数学】【模拟】
万万没想到这道题暴力我就过了。
0ms是计算在x为公差的情况下每位数会有几个数列中的数(例如x=3,369121518...一位数就有3个)
直接计算第y个数字是包含在几位数的等差数列中,是第几个数字。
暴力:
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 104
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
LL sum;
LL e[N];
int get(LL x)
{
int i=;
while(x>=e[i+])i++;
return i;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
e[]=,e[]=;
for(i=;i<=;i++)e[i]=e[i-]*;
while(~scanf("%d",&n))
{
scanf("%d",&m);
i=;
j=get(n);
for(sum=n;i<m;sum+=n,i+=j)
{
if(sum>=e[j+])j++;
}
sum-=n;
if(i==m)printf("%d\n",sum%);
else
{
i=m-(i-j);
printf("%d\n",sum/e[j-i+]%);
}
}
return ;
}
/*
// //
*/
千万不要点
数学:
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 104
using namespace std;
typedef long long LL;
LL cas,cass;
LL n,m,lll,ans;
LL s[];
LL x;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
LL i,j;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%lld",&n))
{
scanf("%lld",&m);
if(n==)
{
puts("");
continue;
}
for(i=,x=;i<;i++,x*=)
s[i]=(x-)/n;
for(i=;i>;i--)
s[i]-=s[i-];
for(i=,x=;i< && m>=s[i]*i;i++)
m-=s[i]*i,x+=s[i]*n;
x+=m/i*n;
if(m%i==)
{
printf("%d\n",x%);
continue;
}
x+=n;
i-=m%i;
while(i--)x/=;
printf("%d\n",x%);
}
return ;
}
/*
// //
*/
千万不要点
【数学】【模拟】XMU 1044 伪伪随机数产生器的更多相关文章
- 【数学】XMU 1593 找数字
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1593 题目大意: T组数据,n个数,只有一种出现q次,其余的出现p次.(1<=T ...
- 【数学】XMU 1597 GCD
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1597 题目大意: 求(am-bm, an-bn),结果取模1000000007,a,b ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- zzulioj--1825-- 会长爱数学(模拟)
1825: 会长爱数学 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 6 Solved: 2 SubmitStatusWeb Board Descr ...
- 数学&模拟:随机化-矩阵随机化
BZOJ2396 给出三个行数和列数均为N的矩阵A.B.C,判断A*B=C是否成立 随机生成一个N乘1的矩阵R 然后判断A*B*R是否等于C*R,而前者相当于A*(B*R) 与后者一样都可以在O(N2 ...
- 2017ACM暑期多校联合训练 - Team 2 1008 HDU 6052 To my boyfriend (数学 模拟)
题目链接 Problem Description Dear Liao I never forget the moment I met with you. You carefully asked me: ...
- CF 990A. Commentary Boxes【数学/模拟】
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...
- CF 450E Jzzhu and Apples 数学+模拟
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [CSP-S模拟测试]:砍树(数学+模拟)
题目传送门(内部题1) 输入格式 第一行两个整数$n$,$k$,代表树苗的数量和最大看书的总长度.第二行n个整数$a_i$,代表林先森希望每棵树苗的最终高度. 输出格式 一行一个整数,代表最大可能的d ...
随机推荐
- [转] git reset简介
http://blog.csdn.net/hudashi/article/details/7664464 http://guibin.iteye.com/blog/1014369 http://hi. ...
- 在cmd窗口下运行Java程序时无法找到主类的解决办法
我是Java的初学者,昨天在cmd窗口下运行一段Java程序时总是有问题,可以编译但无法执行. 也就是javac时正确,一旦java时就不对了,提示找不到或无法加载主类,经百度谷歌再加上自己的摸索终于 ...
- 在Ubuntu上安装使用Systemtap
因为最近开始学习Nginx,在网上看到别人介绍了一款强大的内核探测工具Systemtap,于是便准备学习下这款探测工具为以后代码分析做准备. 第一步便是安装.在自己电脑上安装的时候,也是费了一番劲儿. ...
- KMP和扩展KMP【转】
这种东西基本上在纸上自己推导一下就能做出来XD 转发注明出处 KMP 给出两个字符串A(称为模板串)和B(称为子串),长度分别为lenA和lenB,要求在线性时间内,对于每个A[i] (0<=i ...
- 请输出in.txt文件中的2 4 6 8 9 10 12行
in.txt文件: 学号 姓名 性别 年龄 1001 张三 男 18 1002 赵四 男 19 1003 李丽 女 18 1004 刘芳 女 32 1005 王五 男 54 1006 小明 男 32 ...
- 构建可比较的对象(IComparable)
IComparable接口 System.IComparable接口指定了一种允许一个对象可基于某些特定键值进行排序的行为. namespace System { [ComVisible(true)] ...
- .net框架介绍
.net 一般指 .net Framework框架,是一种平台,一种技术 C# 是一种编程语言,可以开发基于.net平台的应用 Java 既是一种技术,也是一种语言 .net可以开发桌面应用程序 ...
- try{...} catch {...} finally{...} 各种情况代码的执行情况
try { int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("in the 'try'"); } ca ...
- Linq101-Projection
using System; using System.Linq; namespace Linq101 { class Projection { /// <summary> /// This ...
- 编写高效SQL最佳实践
编写高效 SQL 语句的最佳实践 秦玮, 高级软件工程师, IBM 王广成, 软件工程师, IBM 王韵婷, 高级软件工程师, IBM 简介: 本文列举了一些在编写 SQL 查询语句时可能导致 DB2 ...