ACM_20190731and0803_数学

A - Harmonic Number LightOJ - 1234
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:

在这里插入图片描述
在这里插入图片描述

In this problem, you are given n, you have to find Hn.

Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 108).

Output
For each case, print the case number and the nth harmonic number. Errors less than 10-8 will be ignored.

Sample Input

12
1
2
3
4
5
6
7
8
9
90000000
99999999
100000000

Sample Output

Case 1: 1
Case 2: 1.5
Case 3: 1.8333333333
Case 4: 2.0833333333
Case 5: 2.2833333333
Case 6: 2.450
Case 7: 2.5928571429
Case 8: 2.7178571429
Case 9: 2.8289682540
Case 10: 18.8925358988
Case 11: 18.9978964039
Case 12: 18.9978964139
这个题感觉不是很难,以前没碰到过就搜了一下看到了别人的思路
主要就是用到了欧拉函数, 需要注意的是,欧拉函数在很大时才会成立, 故小于10000时还需判断。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const double c = 0.57721566490153286060651209;
double ans[10000];
void ff(){
	memset(ans, 0, sizeof(ans));
	for(int i = 1; i < 10000; i++){
		ans[i] = ans[i-1] + 1.0/i;
	}
}
int main(){
	int t;
	cin>> t;
	int n;
	ff();
	for(int i = 1; i <= t; i++){
		cin>> n;
		if(n < 10000)
			printf("Case %d: %.10f\n", i, ans[n]);
		else 
			printf("Case %d: %.10f\n", i, log(n)+c+1.0/(2*n));
	}
	return 0;
} 

A - Factorial HDU - 1124 The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.
ACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called “Travelling Salesman Problem” and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1.2.3.4…N. The number is very high even for a relatively small N.

The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function.

For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1<N2, then Z(N1) <= Z(N2). It is because we can never “lose” any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.
Input
There is a single positive integer T on the first line of input. It stands for the number of numbers to follow. Then there is T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.
Output
For every number N, output a single line containing the single non-negative integer Z(N).
Sample Input

6
3
60
100
1024
23456
8735373

Sample Output

0
14
24
253
5861
2183837

AC代码:

#include<bits/stdc++.h>
using namespace std;//求N!的末尾有几个0 
					// 10 = 2 * 5
					//2的个数大于5 
int main(){
	int t, cnt, n;
	cin>> t;
	while(t--){
		cnt = 0;
		cin>> n;
		for(int i = 5; i <= n; i*=5){
			cnt += n/i;
		}
		cout<< cnt <<endl; 
	} 
	return 0;
}

B - Goldbach`s Conjecture LightOJ - 1259
Goldbach’s conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:

Every even integer, greater than 2, can be expressed as the sum of two primes [1].

Now your task is to check whether this conjecture holds for integers up to 107.

Input
Input starts with an integer T (≤ 300), denoting the number of test cases.

Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).

Output
For each case, print the case number and the number of ways you can express n as sum of two primes. To be more specific, we want to find the number of (a, b) where

  1.  Both a and b are prime
    
  2.  a + b = n
    
  3.  a ≤ b
    

Sample Input

2
6
4

Sample Output

Case 1: 1
Case 2: 1

Note

  1.  An integer is said to be prime, if it is divisible by exactly two different integers. First few primes are 2, 3, 5, 7, 11, 13, ...
    

思路:
数组必须写成bool,因为int占四个字节。
还有一点就是, 1e7中的素数肯定少于1e7/2,所以这样就不会TLE了。

AC代码:

#include<bits/stdc++.h>
using namespace std;//素数筛 
#define N 10000005
bool a[N];
int prime[666666];
int main(){
	int t, n, h, k = 1, num = 0, l = 0;
	for(int i = 2; i <= 10000000;i++){
		if(a[i] == false){
			prime[l++] = i;
			for(int j = i*2; j <= 10000000; j += i){
				a[j] = true; 
			}
		}
	}
	a[0] = a[1] = true;
	cin>> t;
	while(t--){
		num = 0;
		cin>> n;
		for(int i = 0; i < l; i++){
			if(prime[i] >= n/2+1){
				break;
			}
			h = n - prime[i];
			if(a[h] == false){
				num++;
			}
		}
		printf("Case %d: %d\n", k, num);
		k++;
	}
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在MATLAB中实现机械臂的仿真可以使用Robotic System Toolbox来进行。Robotic System Toolbox包含许多工具和函数,可以实现机械臂的建模、控制和仿真。 首先,需要定义机械臂的模型。可以使用robotics.RigidBodyTree类来创建机械臂的刚体树结构。通过添加关节和刚体可以构建机械臂的结构。可以使用函数robotics.RigidBody来创建刚体,并使用函数robotics.Joint来创建关节。 接下来,可以使用robotics.RigidBodyTree类中的函数来定义机械臂的初始状态。可以设置每个关节的初始位置和速度。 然后,可以使用robotics.RigidBodyTree类中的函数来进行机械臂的运动控制。可以使用函数robotics.InverseKinematics来实现逆运动学,根据目标位置和姿态来求解关节角度。可以使用函数robotics.CartesianTrajectory来生成机械臂的轨迹,指定起始和目标位置以及运动时间。 最后,可以使用robotics.RigidBodyTree类中的函数来进行机械臂的仿真。可以使用函数robotics.Rate来指定仿真的频率,然后使用循环来更新机械臂的状态和控制输入,实现机械臂的运动。 以下是一个基本的机械臂仿真的示例代码: ```matlab % 创建机械臂模型 robot = robotics.RigidBodyTree; % 添加机械臂的关节和刚体 % 设置机械臂的初始状态 % 运动控制 % 仿真循环 % 绘制机械臂的运动轨迹 ``` 在实际的机械臂仿真中,可能还需要考虑机械臂的动力学、碰撞检测和路径规划等问题。可以使用Robotic System Toolbox中的其他工具和函数来处理这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值