Input: Standard Input Output: Standard Output � There is a rectangle on the cartesian plane, with bottom-left corner at (0,0) and top-right corner at (L,W). There is a ball centered at (x, y), with radius=R, shown below At time 0, the ball starts to…
Ball Blasting Game Morteza is playing a ball blasting game. In this game there is a chain of different colored balls. He is expected to explode as many balls as possible by aligning same-colored balls and making a sequence of them. To align balls, he…
给定两个整数m和n,求最大的k使得m^k是n!的约数 对m质因子分解,然后使用勒让德定理求得n!包含的质数p的阶数,min(b[i] / a[i])即为结果k, 若为0无解 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<map> #in…
大一刚开始接触ACM就买了<算法竞赛入门经典>这本书,当时只能看懂前几章,而且题目也没做,粗鄙地以为这本书不适合自己.等到现在快大三了再回过头来看,发现刘老师还是很棒的! 扯远了... 题意:问f[a^b]%n的值,f为斐波那契数.根据f[i]=f[i-1]+f[i-2]不难发现,当二元组(f[i],f[i-1])出现重复时,整个序列就开始重复了.如n=3,序列f[i]的前10项为 0,1,1,2,0,2,2,1,0,1 f[9]和f[10]与前两项一样. 那么周期会在哪出现呢?从n项中取2项…
Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They have have decided to sit everyone around a circular table. First, everyone has converted all of their properties to coins of equal value, such that th…
题目链接: https://cn.vjudge.net/problem/UVA-10217 题目大意: 有若干人排队买电影票,如果某个人的生日与排在他前面的某个人的生日相同,那么他讲中奖.中奖的机会只有一个,给所有中奖者中排在最前面的那一位.排在第一位的人如果与买票者的生日相同,那么他将中奖.如果一年有N天,求排在什么位置的中奖概率最大,和理论上的最佳实数位置. 解题思路: f[1] = 1/n; f[2] = (n-1)/n * 1/n; ... f[i] = (n-1)/n * (n-1)/…
Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name of Kernighan and Ritchie, the authors of The C Programming Language. While coding in C, we use different control statements and loops, such as, if-the…
Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const int N=4000002; long long sumv[maxn],f[maxn]; int phi[maxn],prime[maxn],vis[maxn]; void solve(){ phi[1]=1; int cnt=0; for(int i=2;i<=R;++i){ if(!vis[i])…
 目录 1 三角形面积 2 立方变自身 3 三羊献瑞 4 九数组分数 5 饮料换购 6 生命之树   前言:以下试题解答代码部分仅供参考,若有不当之处,还请路过的同学提醒一下~ 1 三角形面积 三角形面积 如[图1]所示.图中的所有小方格面积都是1. 那么,图中的三角形面积应该是多少呢? 请填写三角形的面积.不要填写任何多余内容或说明性文字. 简单的数学平面几何问题: 大正方形面积-三个三角形面积 = 最终结果 2 立方变自身 立方变自身 观察下面的现象,某个数字的立方,按位累加仍然等于自身.…
题目链接: F. Couple Cover time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a recta…
Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a rectangle. A bag with nballs, each with an integer written on it, is placed on the table. The first player reaches in and grabs a ball ra…
解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.三角形面积 题目描述 如图1所示.图中的所有小方格面积都是1. 那么,图中的三角形面积应该是多少呢? 请填写三角形的面积.不要填写任何多余内容或说明性文字. 28 简单的数学平面几何问题: 大正方形面积-三个三角形面积 = 最终结果 题目2.立方变自身 题目描述 观察下面的现象,某个数字的立方,按位累加仍然等于自身. 1^3 = 1 8^3 = 512 5+1+2=8 17^3 = 4913 4+9+1+3=17 - 请你计算包括…
三角形面积 题目描述 如图1所示.图中的所有小方格面积都是1. 那么,图中的三角形面积应该是多少呢? 请填写三角形的面积.不要填写任何多余内容或说明性文字. 28 简单的数学平面几何问题: 大正方形面积-三个三角形面积 = 最终结果…
前者之所以叫加强版,就是把uva1027改编了,附加上打印路径罢了. 03年的final题哦!!虽然是水题,但不是我这个只会做图论题的跛子能轻易尝试的——因为有个数学坑. 题意:运送x个货物从a->b,沿途要上交过路费,village(小写字母)只需交一个单位的货物,town(大写字母)要交(x/20+((x%20==0)?0:1))个单位的货物,即每20个货物要上交一个,不足的按20处理.现在已知要送到b点y个货物,那么最少从x出发要携带多少个货物. 注意: 1.路过town:19=20-1,…
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu id=19100" style="color:blue">Submit Status Description  Simple calculations  id=19100" style="color:blue">The Pro…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4514 题意: 有两个盒子各有n(1≤n≤2e5)个糖,每天随机选一个(概率分别为p,1-p),然后吃一颗糖.直到有一天,打开盒子一看,没糖了!输入n,p,求此时另一个盒子里糖的个数的数学期望. 分析: 根据期望的定义,不妨设最后打开第1个盒子,此时第2个盒子有i颗,则这之前打开过n…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3382 题意: 你住在村庄A,每天需要过很多条河到另一个村庄B上班.B在A的右边,所有的河都在中间.幸运的是,每条河上都有匀速移动的自动船,因此每当到达一条河的左岸时,只需等船过来,载着你过河,然后在右岸下船.你很瘦,因此上船之后船速不变.日复一日,年复一年,你问自己:从A到B,平均…
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问题 |00|+|01|=|0| 注意序列是环形 // // main.cpp // poj3869 // // Created by Candy on 25/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <i…
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll…
大致题意:给出几个包裹,每个包裹都包装好了3种大小的杯子.现在要重新包装,使向量 a[1]*(s[1][1],s[1][2],s[1][3])+a[2]*(s[2][1],s[2][2],s[2][3])+.....+a[n]*(s[n][1],s[n][2],s[n][3])=(k,k,k). 就这样转化成了向量问题其中a[i]为非负整数,k为正整数. 虽然转化成了向量问题,但是三维向量和这么多变量有点棘手,所以我们可以先降维,将原等式变化成: a[1]*(s[1][2]-s[1][1],s[…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4763 题意:给你一个区间L,R:求区间所有数的并,和或的答案: 思路:两个数的二进制长度不一样,显然是2^(len(r))-1,0: 长度一样取前面相等的部分,或后面填1,且后面填0即可: 跟某场CCPC区间(L,R)取两个数,好像是一样的: #include<bits/s…
Power of Cryptography  Background Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers modulo functions of these primes. Work in this area has resulted in the practical use of results from num…
UVa 1262  Password 题目: Password   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  Shoulder-surfing is the behavior of intentionally and stealthily watching the screen of another person's electronic…
UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路: maxn=10000 如果计算maxn!再保存的话显然装不下. 但答案由阶乘的积或商组成,所以可以用唯一分解定理求解.大题思路就是把目前答案的质因子的指数用数组e保存,乘除都对e操作. 需要注意的是筛法求素数优化后的写法. 代码: #include<iostream> #include<…
UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出公式,设圆弧扇形部弧度r,那么能够计算出铁棒长度为lr/sin(r)这个公式在[0, pi/2]是单调递增的,所以能够用二分法去求解 要注意的一点是最后答案计算过程中带入mid,之前是带入x(二分的左边值),可实际上x是可能等于0的,而带入mid,因为是double型,所以mid实际上表示是一个很趋…
UVA 1524 - Hot or Cold? 题目链接 题意:给一个一元n次方程,带入x表示时间,f(x)表示温度,如今要求[s, e]的平均温度 思路:平均温度就是 总温度/ (e - s),画出曲线,能够发现温度总和为[s,e]上区间与x轴围成的面积,那么利用f(x)的原函数就能求面积了 代码: #include <cstdio> #include <cstring> #include <cmath> const int N = 105; int n; doubl…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题意 输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数.直到输入0 0时程序结束 分析: 如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6. 下面给出AC代码: #include <bits/stdc++.h&…
题目链接 题目要求: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value…
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定要竭尽全力地去刷题,当然,也是能好好刷题的最后时间了. [题目链接]Colossal Fibonacci Numbers [题目类型]数学 &题意: 求Fi(f(a^b)%n) Fi()是斐波那契 &题解: 注意:unsigned时 要把%d全换成%u 数学大法好. 首先你要能看出来这是有循环…
题意:给定一个整数 n ,然后你要把它变成 1,变换操作就是随机从小于等于 n 的素数中选一个p,如果这个数是 n 的约数,那么就可以变成 n/p,否则还是本身,问你把它变成 1 的数学期望是多少. 析:一个很明显的期望DP,dp[i] 表示把 i 变成 1 的期望是多少,枚举每一种操作,列出表达式,dp[i] = ∑dp[i/x]/q + p/q*dp[i] + 1,其中 x 表示枚举的素数,然后 p 表示不是 i 的约数个数,q 是小于等于 n 的素数个数,然后变形,可以得到 dp[i] =…