简单问题窥见数学
51 nod 是个好的学习网站,不仅算法分级,而且可以查看别人的优秀代码(过了之后才能查看)。接下来的一些问题就是来自那里。
51 nod 1413 权势二进制(简单数字游戏·贪心)
题目:(1<=n<=1,000,000)
Output
输出答案占一行。
Input示例
9
Output示例
9
分析:简单的讲,权势二进制就是只由0和1组成的十进制数。有点贪心的意思:比投153=111+11*2+10*2;135=111+11*2+1*2
import java.util.*;public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str; int [] m=new int [7]; while(sc.hasNext()){ str=sc.next(); Arrays.fill(m,0); int length=str.length(); for(int i=0;i0){ ans+=m[i]; for(int j=i+1;j51nod 1381 硬币游戏(简单概率)
R <= 10,000,000,000)
Output
对于每一个数据,在一行中输出答案的整数部分即可。
Input示例
11
Output示例
2
分析:因为r是一个整数,所以问题好想的多,圆和直线相交的个数有2r+1(相切)和2r两种结果,后者有一个单位长度的线段概率,前者只有一个点的概率。所以答案就是2r.
接下来的一个问题是比赛遇到的:Rectangle
frog has a piece of paper divided into n rows and m columns. Today, she would like to draw a rectangle whose perimeter is not greater than k.
There are 8(out of 9) ways when n=m=2,k=6 Find the number of ways of drawing.
Input
The input consists of multiple tests. For each test:
The first line contains
3
integer
n,m,k
(1≤n,m≤5⋅104,0≤k≤109).
Output
For each test, write
1
integer which denotes the number of ways of drawing.
Sample Input
2 2 61 1 050000 50000 1000000000
Sample Output
801562562500625000000分析:
继续设想:当i=3呢,那么(m-1+1)-->(m-3+1);所以设q=min(n,k/2-1),j=k/2-i。
51nod 1393 0和1相等串
0 0 0 1
0 1 0 -1 -2 -1
计算数据反映了变化的趋势。 寻找sum[i]=sum[j] 长度就是最大的j-i.
#include //一定要让计算数据变化#include #include #include
暂时没有评论,来抢沙发吧~