19级算法训练赛第七场

电源新手别怕!手把手教你搞定Buck电路的环路补偿(附Type II/III补偿器参数计算) 本文为电源设计新手详细解析Buck电路环路补偿技术,重点介绍Type II和Type III补偿器的参数计算与设计方法。通过实例演示和实用技巧,帮助工程师快速掌握环路补偿原理,解决电源振荡、响应慢等问题,提升电路稳定性与性能。 阅读详情

19级算法训练赛第七场

传送门:https://vjudge.net/contest/362412#problem/J

A - 程序设计:合并数字

蒜头君得到了 n 个数,他想对这些数进行下面这样的操作,选出最左边的相邻的差的绝对值为 1 的两个数,只保留较小的数,删去较大的数,直到没有两个相邻的差的绝对值为 1 的数,问最多可以进行多少次这样的操作?
输入格式
输入第一行为一个整数 n(1 \leq n \leq 10^5)n(1≤n≤10 5),表示数字的总数
第二行为 n个整数 x_1,x_2,…,x_n(0 \leq x_i \leq 10^9)x 1 ,x 2,…,x n (0≤x i ≤10 9 ),表示这些数。
样例输入
4
1 2 0 1
样例输出
3

栈的运用

#include<bits/stdc++.h>
using namespace std;
stack<int> s;
int main(){
	int n,m,cnt=0;
	cin>>n;
	while(n--){
		cin>>m;
		while(!s.empty()&&s.top()-m==1){
			s.pop();
			cnt++;
		}
		if(!s.empty()&&m-s.top()==1) cnt++;
		else s.push(m);
	} 
	cout<<cnt<<endl;
	return 0;
}

B - 程序设计:找质数

一天蒜头君猜想,是不是所有的偶数(除了 2),都可以用两个质数相加得到呢?于是聪明的蒜头君就找你来验证了。

输入格式
第一行输入一个整数 t 表示测试组数。

接下来 tt 行,每行一个整数 n。

输出格式
输出两个整数,因为答案可能有多个,所有要求输出的这两个整数是所有答案中字典序最小的。

数据范围
对于 30%30% 的数据 1 \le t \le 10^31≤t≤10 3 。

对于 60%60% 的数据 1 \le t \le 10^51≤t≤10 5 。

对于 100%100% 的数据 1 \le t \le 10^6, 4 \le n \le 10^61≤t≤10 6 ,4≤n≤10 6,n为偶数。

。。。坑
先用质数筛打个表,多次询问且数值大,要用scanf,printf才不会超时

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
bool flag[maxn];
int prime[maxn/10];
void getPrime(){//函数欧拉筛找质数
    memset(flag,0,sizeof(flag));
    int cnt=0;
    for(int i=2;i*i<=maxn;i++)
        if(!flag[i])
            for(int j=i*i;j<=maxn;j+=i)
                flag[j]=1;
    for(int i=2;i<=maxn;i++)
        if(!flag[i]) prime[cnt++]=i;
}
int main(){
    getPrime();
    int t,num;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&num);
        for(int i=0;prime[i]<=num/2;i++){
        	if(!flag[num-prime[i]]){
            	printf("%d %d\n",prime[i],num-prime[i]);
            	break;
			}	
		}     
    }
    return 0;
}

C - Red and Black

There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

‘.’ - a black tile
‘#’ - a red tile
‘@’ - a man on a black tile(appears exactly once in a data set)
Output
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
Sample Input
6 9
…#.
…#
…
…
…
…
…
#@…#
.#…#.
11 9
.#…
.#.#######.
.#.#…#.
.#.#.###.#.
.#.#…@#.#.
.#.#####.#.
.#…#.
.#########.
…
11 6
…#…#…#…
…#…#…#…
…#…#…###
…#…#…#@.
…#…#…#…
…#…#…#…
7 7
…#.#…
…#.#…
###.###
…@…
###.###
…#.#…
…#.#…
0 0
Sample Output
45
59
6
13

深度搜索,水洼问题

#include<bits/stdc++.h>
using namespace std;
char c[23][23];
int vis[23][23];
int d[][2]={{-1,0},{0,-1},{0,1},{1,0}};
int n,m,cnt;
void dfs(int x,int y){
	cnt++;
	vis[x][y]=1;
	for(int i=0;i<4;i++)
		if(x+d[i][0]>=0&&y+d[i][1]>=0&&x+d[i][0]<m&&y+d[i][1]<n&&c[x+d[i][0]][y+d[i][1]]!='#'&&vis[x+d[i][0]][y+d[i][1]]!=1){
			dfs(x+d[i][0],y+d[i][1]);
		}
	return ;
}
int main(){
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		memset(vis,0,sizeof(vis));
		int x0,y0;
		cnt=0;
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cin>>c[i][j];
				if(c[i][j]=='@'){
					x0=i;y0=j;
				}
			}
		}
		dfs(x0,y0);
		cout<<cnt<<endl;
	}	
	return 0;
}

D - Game 23

Polycarp plays “Game 23”. Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves.

Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so.

It is easy to prove that any way to transform n to m contains the same number of moves (i.e. number of moves doesn’t depend on the way of transformation).

Input
The only line of the input contains two integers n and m (1≤n≤m≤5⋅108).

Output
Print the number of moves to transform n to m, or -1 if there is no solution.

Examples
Input
120 51840
Output
7
Input
42 42
Output
0
Input
48 72
Output
-1
Note
In the first example, the possible sequence of moves is: 120→240→720→1440→4320→12960→25920→51840. The are 7 steps in total.

In the second example, no moves are needed. Thus, the answer is 0.

In the third example, it is impossible to transform 48 to 72.

题目要求就是输入两个数,问你从第一个数变成第二个数需要几步,变化的方法是乘以2或者乘以3,如果可以,输出步数,不可以的话就输出“-1”
我觉得主要是思维?

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n,m,cnt=0;
	cin>>n>>m;
	if(m%n!=0) cout<<-1<<endl;
	else{
		int r=m/n;
		for(int i=2;i<=3;i++){
			while(r%i==0){
				cnt++;
				r/=i;	
			}
		}
		if(r>1) cout<<-1<<endl;
		else cout<<cnt<<endl;
	}
	return 0;
}

E - 棋盘问题

在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。
Input
输入含有多组测试数据。
每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n
当为-1 -1时表示输入结束。
随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域(数据保证不出现多余的空白行或者空白列)。
Output
对于每一组数据,给出一行输出,输出摆放的方案数目C (数据保证C<2^31)。
Sample Input
2 1
#.
.#
4 4
…#
…#.
.#…
#…
-1 -1
Sample Output
2
1

变种八皇后

#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
int n,k,cnt;
int vis[10];
char c[10][10];
void dfs(int h,int x){//h代表第几行,x代表个数
	if(x==k){
		cnt++;
		return ;
	}
	if(h>n){
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0&&c[h][i]=='#'){
			vis[i]=1;//相当于i这一列被占了 
			dfs(h+1,x+1);
			vis[i]=0;
		}
	}
	dfs(h+1,x);
}
int main(){
	while(cin>>n>>k){
		if(n==-1&&k==-1) break;
		cnt=0;
		memset(vis,0,sizeof(vis));
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin>>c[i][j];
			}	
		}
		dfs(1,0);
		cout<<cnt<<endl;
	} 
	return 0;
}

F - Super Jumping! Jumping! Jumping!

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3

求解最大递增子序列和,需要注意的是不用是连续的。

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
int a[1008],dp[1008];
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		memset(a,0,sizeof(a));
		memset(dp,0,sizeof(dp));
		int m=-maxn;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++){
			dp[i]=a[i];
			for(int j=1;j<=i;j++){
				if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+a[i]);
			}
			if(dp[i]>m) m=dp[i];
		}
		cout<<m<<endl;
	}
	return 0;
}

G - Primes

Write a program to read in a list of integers and determine whether or not each number is prime. A number, n, is prime if its only divisors are 1 and n. For this problem, the numbers 1 and 2 are not considered primes.
Input
Each input line contains a single integer. The list of integers is terminated with a number<= 0. You may assume that the input contains at most 250 numbers and each number is less than or equal to 16000.
Output
The output should consists of one line for every number, where each line first lists the problem number, followed by a colon and space, followed by “yes” or “no”.
Sample Input
1
2
3
4
5
17
0
Sample Output
1: no
2: no
3: yes
4: no
5: yes
6: yes

质数判断

#include<bits/stdc++.h>
using namespace std;
bool pd(long long num){/*速度最快*/ 
    if(num==1||num==2) return 0;
    if(num==3) return 1;   
    if(num%6!=1&&num%6!=5) return 0 ;  
    int tmp=sqrt(num);
    for(int i=5;i<=tmp;i+=6){
    	if(num%i==0||num%(i+2)==0) return 0;
    }
    return 1 ;
}
int main(){
	int n,cnt=1;
	while(cin>>n&&n>0){   
		if(pd(n)) printf("%d: yes\n",cnt);
		else printf("%d: no\n",cnt);
		cnt++;
	}
	return 0;
}

H - WeirdSort

You are given an array a of length n.

You are also given a set of distinct positions p1,p2,…,pm, where 1≤pi<n. The position pi means that you can swap elements a[pi] and a[pi+1]. You can apply this operation any number of times for each of the given positions.

Your task is to determine if it is possible to sort the initial array in non-decreasing order (a1≤a2≤⋯≤an) using only allowed swaps.

For example, if a=[3,2,1] and p=[1,2], then we can first swap elements a[2] and a[3] (because position 2 is contained in the given set p). We get the array a=[3,1,2]. Then we swap a[1] and a[2] (position 1 is also contained in p). We get the array a=[1,3,2]. Finally, we swap a[2] and a[3] again and get the array a=[1,2,3], sorted in non-decreasing order.

You can see that if a=[4,1,2,3] and p=[3,2] then you cannot sort the array.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤100) — the number of test cases.

Then t test cases follow. The first line of each test case contains two integers n and m (1≤m<n≤100) — the number of elements in a and the number of elements in p. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤100). The third line of the test case contains m integers p1,p2,…,pm (1≤pi<n, all pi are distinct) — the set of positions described in the problem statement.

Output
For each test case, print the answer — “YES” (without quotes) if you can sort the initial array in non-decreasing order (a1≤a2≤⋯≤an) using only allowed swaps. Otherwise, print “NO”.

Example
Input
6
3 2
3 2 1
1 2
4 2
4 1 2 3
3 2
5 1
1 2 3 4 5
1
4 2
2 1 4 3
1 3
4 2
4 3 2 1
1 3
5 2
2 1 2 3 3
1 4
Output
YES
NO
YES
YES
NO
YES

输入两个数n和m
第二行n个数,表示长度为n的数组a
第三行m个数,p1,p2,p3…pm,每个数表示长度为n的数组中a[pi]可以和a[pi+1]互换
只允许进行m中互换,问能否实现a数组的从小到大排序
有is_sorted()函数的运用(判断一个数组是否从小到大有序),真是太方便辣!

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int a[103],p[103];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=m;i++) cin>>p[i];
		for(int i=1;i<=n;i++)
   			for(int j=1;j<=m;j++)
    			if(a[p[j]]>a[p[j]+1]) swap(a[p[j]],a[p[j]+1]);
    	if(is_sorted(a+1,a+n+1)) puts("YES");
		else puts("NO"); 
	}
	return 0;
}

I - Integer Divisibility

If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a sequence of only a digit. Now you are given the number and the only allowable digit, you should report the number of digits of such multiple.

For example you have to find a multiple of 3 which contains only 1’s. Then the result is 3 because is 111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7 which contains only 3’s then, the result is 6, because 333333 is divisible by 7.

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

Each case will contain two integers n (0 < n ≤ 106 and n will not be divisible by 2 or 5) and the allowable digit (1 ≤ digit ≤ 9).

Output
For each case, print the case number and the number of digits of such multiple. If several solutions are there; report the minimum one.

Sample Input
3

3 1

7 3

9901 1

Sample Output
Case 1: 3

Case 2: 6

Case 3: 12

翻译
如果整数不能被2或5整除,则十进制表示法中该数字的某个倍数只是一个数字的序列。现在您将获得数字和唯一允许的数字,您应该报告此数字的位数。
例如,您必须找到仅包含1的3的倍数。然后结果是3,因为111(3位)可被3整除。同样,如果你发现7的多数只包含3的那么,结果是6,因为333333可以被7整除

大数整除

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;

int main(){
	int t;
	cin>>t;
	for(int i=1;i<=t;i++){
		ll n,m,d=0,b=1,temp=0;
		cin>>n>>m;
		while(b){
			temp=(temp*10+m)%n;
			b=temp;
			d++;
		}
        printf("Case %lld: %lld\n",i,d);
	}
	return 0;
}

J - Pie

My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.

My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size.

What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.
Input
One line with a positive integer: the number of test cases. Then for each test case:
—One line with two integers N and F with 1 <= N, F <= 10 000: the number of pies and the number of friends.
—One line with N integers ri with 1 <= ri <= 10 000: the radii of the pies.
Output
For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10^(-3).
Sample Input
3
3 3
4 3 3
1 24
5
10 5
1 4 2 3 4 5 6 5 4 2
Sample Output
25.1327
3.1416
50.2655

分到最大馅饼的体积是:所有馅饼体积之和/(F+1);(为什么不能是直接所有馅饼之和/(F+1)呢?因为每人只能分到一块,如果讲究平均分的话,一个人分到的就是拼凑起来的“最大的体积”,一个人甚至可能得到超过一块馅饼)最小即为0,然后我们对这两个最大最小值采用二分方法,求出中间符合最大的体积。那么怎么判断那个值就是最大的体积呢?让每个馅饼的体积/能分到最大的体积=能分到的人数,然后将每个馅饼能分到的人数相加,将该人数与F+1做判断比较//转自「聪明绝顶的你与即将秃头的我」
二分(还是有点不懂)

#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
double v[10008];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,f;
		double right,left=0.0,mid;
		cin>>n>>f;
		f++;
		for(int i=1;i<=n;i++){
			int r;
			cin>>r;
			v[i]=pi*r*r;
			right+=v[i];
		}
		right/=f;
		while(right-left>1e-6){
			int sum=0;
			mid=(right+left)/2.0;
			for(int i=1;i<=n;i++) sum+=(int)(v[i]/mid);
			if(sum>=f) left=mid;
			else right=mid;
		}
		printf("%.4lf\n",mid);
	}
	return 0;
}

K - 水果

夏天来了好开心啊,呵呵,好多好多水果
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
Input
第一行正整数N(0<N<=10)表示有N组测试数据.
每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
Sample Input
1
5
apple shandong 3
pineapple guangdong 1
sugarcane guangdong 1
pineapple guangdong 3
pineapple guangdong 1
Sample Output
guangdong
|----pineapple(5)
|----sugarcane(1)
shandong
|----apple(3)

map的嵌套(套了个结构体)重要

#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
struct fruit{//存放水果和数量 
	map<string,int>fruitma;
};
map<string,fruit> ma;
int main(){
	int t;
	cin>>t;
	while(t--){
		ma.clear();
		int n;
		cin>>n;
		//存放地名和水果 
		for(int i=1;i<=n;i++){
			string sg,dm;
			int cnt;
			cin>>sg>>dm>>cnt;
			ma[dm].fruitma[sg]+=cnt;
		}
		map<string,fruit>::iterator it;
		map<string,int>::iterator fruitmait;
		for(it=ma.begin();it!=ma.end();it++){
			cout<<it->first<<endl;
			for(fruitmait=it->second.fruitma.begin();fruitmait!=it->second.fruitma.end();fruitmait++){
				cout<<"   |----"<<fruitmait->first<<"("<<fruitmait->second<<")"<<endl;
			}
		}
		if(t!=0) cout<<endl;
	}
	return 0;
}

L - Dead Pixel

Screen resolution of Polycarp’s monitor is a×b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x,y) (0≤x<a,0≤y<b). You can consider columns of pixels to be numbered from 0 to a−1, and rows — from 0 to b−1.

Polycarp wants to open a rectangular window of maximal size, which doesn’t contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.

Print the maximal area (in pixels) of a window that doesn’t contain the dead pixel inside itself.

Input
In the first line you are given an integer t (1≤t≤104) — the number of test cases in the test. In the next lines you are given descriptions of t test cases.

Each test case contains a single line which consists of 4 integers a,b,x and y (1≤a,b≤104; 0≤x<a; 0≤y<b) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that a+b>2 (e.g. a=b=1 is impossible).

Output
Print t integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn’t contain the dead pixel.

Example
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80

思维,一个坏的像素将一个屏幕分成了四个部分,算出最大的那部分。

#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;

int main(){
	int t;
	cin>>t;
	while(t--){
		int a,b,x,y,s1,s2,s3,s4;
		cin>>a>>b>>x>>y;
		s1=a*y;
		s2=a*(b-y-1);
		s3=b*(a-x-1);
		s4=b*x;
		s1=max(s1,s2);
		s3=max(s3,s4);
		cout<<max(s1,s3)<<endl;
	}
	return 0;
}

M - Complete the Sequence

You probably know those quizzes in Sunday magazines: given the sequence 1, 2, 3, 4, 5, what is the next number? Sometimes it is very easy to answer, sometimes it could be pretty hard. Because these “sequence problems” are very popular, ACM wants to implement them into the “Free Time” section of their new WAP portal.
ACM programmers have noticed that some of the quizzes can be solved by describing the sequence by polynomials. For example, the sequence 1, 2, 3, 4, 5 can be easily understood as a trivial polynomial. The next number is 6. But even more complex sequences, like 1, 2, 4, 7, 11, can be described by a polynomial. In this case, 1/2.n^2-1/2.n+1 can be used. Note that even if the members of the sequence are integers, polynomial coefficients may be any real numbers.

Polynomial is an expression in the following form:

P(n) = aD.nD+aD-1.nD-1+…+a1.n+a0

. If aD <> 0, the number D is called a degree of the polynomial. Note that constant function P(n) = C can be considered as polynomial of degree 0, and the zero function P(n) = 0 is usually defined to have degree -1.
Input
There is a single positive integer T on the first line of input. It stands for the number of test cases to follow. Each test case consists of two lines. First line of each test case contains two integer numbers S and C separated by a single space, 1 <= S < 100, 1 <= C < 100, (S+C) <= 100. The first number, S, stands for the length of the given sequence, the second number, C is the amount of numbers you are to find to complete the sequence.

The second line of each test case contains S integer numbers X1, X2, … XS separated by a space. These numbers form the given sequence. The sequence can always be described by a polynomial P(n) such that for every i, Xi = P(i). Among these polynomials, we can find the polynomial Pmin with the lowest possible degree. This polynomial should be used for completing the sequence.
Output
For every test case, your program must print a single line containing C integer numbers, separated by a space. These numbers are the values completing the sequence according to the polynomial of the lowest possible degree. In other words, you are to print values Pmin(S+1), Pmin(S+2), … Pmin(S+C).

It is guaranteed that the results Pmin(S+i) will be non-negative and will fit into the standard integer type.
Sample Input
4
6 3
1 2 3 4 5 6
8 2
1 2 4 7 11 16 22 29
10 2
1 1 1 1 1 1 1 1 1 2
1 10
3
Sample Output
7 8 9
37 46
11 56
3 3 3 3 3 3 3 3 3 3

差分,还得多学哇
在这里插入图片描述

#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
int a[105][105];
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n;i++){
			cin>>a[0][i];
		}
		for(int i=1;i<n;i++){
			for(int j=0;j<n-i;j++){
				a[i][j]=a[i-1][j+1]-a[i-1][j];
				//cout<<a[i][j]<<" ";
			}
			//cout<<endl;
		}
		for(int i=1;i<=m;i++){
			a[n-1][i]=a[n-1][0];
			//cout<<a[n-1][i]<<" ";
		}
		//cout<<endl;
		for(int i=n-2;i>=0;i--){
			for(int j=0;j<m;j++){
				a[i][n-i+j]=a[i][n-i+j-1]+a[i+1][n-i+j-1];
				//cout<<a[i][j+m]<<" ";
			}
			//cout<<endl;
		}
		for(int i=0;i<m-1;i++) cout<<a[0][n+i]<<" ";
		cout<<a[0][n+m-1]<<endl;
	}
	return 0;
}

N - Harmonic Number

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

求f(n)=1/1+1/2+1/3+1/4…1/n (1 ≤ n ≤ 108).,精确到10^-8

欧拉常数,欧拉公式传送门:https://www.cnblogs.com/guxuanqing/p/9440597.html

#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
const double r=0.57721566490153286060651209;//欧拉常数
double a[10000];
int main(){
    a[1]=1;
    for(int i=2;i<10000;i++){//预先把小于10000的f(n)求出来
        a[i]=a[i-1]+1.0/i;
    }
    int n; 
	cin>>n;
    for(int i=1;i<=n;i++){
        int x;
		cin>>x;
        if(x<10000){//n<10000时,可直接得出结果
            printf("Case %d: %.10lf\n",i,a[x]);
        }
        else{//否则利用欧拉公式
            double a=log(x)+r+1.0/(2*x);
            printf("Case %d: %.10lf\n",i,a);
        }
    }
    return 0;
}
034、特定场景优化(一):小目标检测的改进策略合集 本文针对工业场景中的小目标检测难题,提出了一套实战优化方案。首先从数据层面建议保持高分辨率输入(1024-1280像素)或采用切块训练策略,并适当放大标注区域。在网络结构上,提出减少下采样次数、增加高分辨率检测头、引入空间注意力机制等改进。损失函数方面推荐使用NWD匹配和QFL损失提升小目标敏感度。部署环节强调NMS优化、分辨率对齐和量化处理技巧。最后总结核心经验:优先优化数据质量而非模型结构,标注一致性比算法更重要,同时需为实际部署预留性能余量。硬件升级有时比算法调优更经济有效。 阅读详情

相关推荐

BrainVision Recorder 和 BrainVision Analyzer 2.2 安装

本篇为《EEG处理》系列博客的第二篇,该系列博客主要记录EEG信号处理的学习过程中的软件安装和学习过程,方便以后查阅。本篇为BrainVision Recorder 和 BrainVision Analyzer 2.2 的安装过程。 BrainVision Recorder 和 BrainVision Analyzer 2.2 安装安装前奏Brain Vision Analyzer分析软件 安装Brain Vision Recorder记录软件 安装推荐几款个人使用的科研软件 安装前奏 Brain V

梁小憨憨的博客 5074

N皇后问题【递归、搜索】

题目描述 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input 共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。 Output 共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。 输入样例 1 8 5 0 输出样例 1 92 10 AC代码 #include <iostream> #includ

qq_22841387的博客 526

RAG项目简历包装指南:从“流水线工人”到“问题解决者”的跃迁(附代码与思路)

本文代码已在Python 3.11 + CUDA 12.3环境测试,部分功能需LangChain 0.2+支持。

Conan_0728的博客 1890

Numpy练习小例题(2)--创建一个8*8的国际象棋棋盘(黑块为0,白块为1)

【代码】Numpy练习小例题(2)--创建一个8*8的国际象棋棋盘(黑块为0,白块为1)

qq_46044325的博客 9327

jane street market prediction 冠军方案 奇巧淫技与topline链接整理(3/3)

目录前言将income 作为loss(优化目标)读取数据,定义优化目标模型训练与微调提交结果多目标学习Topline整理AE+MLP (rank10)Current 17th solution: Ensembles of deep (49 layer) MLPsmixup augmentation: a way to learn from trades with weight=0 (rank4)My (perhaps) over-complicated LSTM solutionCurrent 62nd .

weixin_51484067的博客 2649

MCGS 昆仑通态触摸屏 modbus TCP 数据转发

MCGS触摸屏数据转发modbus TCP数据转发

m0_63451859的博客 2万+

hdu2553八皇后问题(DFS)

在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Input

T__TSZ的博客 380

断层错动和近断层地震动联合作用下软岩隧洞衬砌损伤分析

摘要 本文提出了一种基于Python的软岩隧洞衬砌损伤分析系统,重点研究断层错动和近断层地震动的联合作用效应。系统采用有限元方法建立隧洞-围岩体系模型,通过非线性动力分析评估衬砌结构损伤。研究内容包括:1)建立考虑应变软化的软岩本构模型;2)基于位错理论模拟断层错动过程;3)合成具有速度脉冲效应的近断层地震动;4)开发完整的动力响应分析流程。结果表明,所提出的方法能有效评估软岩隧洞在复杂地质条件下的抗震性能,为工程设计提供理论依据。 关键词:软岩隧洞、断层错动、近断层地震动、损伤分析、Python、有限元法

max500600的博客 848

UVM实战学习笔记(二)SystemVerilog_Assertion—sequence操作定义(1)

Assertion分类: 1、立即断言:非时序的。如同过程块语句。可以在initial、always、task、function中使用,类似于if语句。 [name : ] assert (expression) [pass_statement] [else fail_statement]. 如assert (a == 1)a = a+1 else a == 1; 通常在else中结合 $fatal/error/warning/info使用。 2、并行断言:时序性的。用property用来区分立即

qq_42001126的博客 2338

【Visual Assist X助手安装问题】Visual Assist X无法安装(双击安装包没反应) | Visual Assist X安装后在Visual Studio中找不到(亲测有效)

本文分享了Visual Assisant X助手的安装与使用问题的详细解决办法,因为网上搜集的信息比较少,所以有一定的参考价值。考虑到很多开发新手会遇到上述问题,可能对Windows系统不熟悉,所以相关操作步骤讲解的很详细!

dvlinker的技术专栏 6万+

【物联网】基于LORA组网的远程环境监测系统设计(ThingsCloud云平台版)_资料编号34

实现一主多从的LORA组网远程通信,主机和两个从机都配备了STM32F103单片机与 LoRa 模块,主机作为中心设备及WIFI网关,负责接收和发送数据到远程物联网平台和手机APP,两个从机则负责采集数据并通过各自的 LoRa组网将数据发送给主机。

嵌入式阿齐Archie 1万+

签到题:game23(动态规划)

Vjudge:动态规划签到题

qq_44654498的博客 320

AXI-5.6 Multiple region interfaces

规则:如果从设备实现的区域少于16个,它必须确保对任何访问未支持区域的尝试都能给出符合协议的响应。具体实现方式由设计者定义。场景:一个错误的软件驱动试图向区域 5(该加密加速器未实现)写入数据。实现方式一:提供错误响应(严格模式)行为:加密加速器检测到AxREGION的值大于2,立即对该事务返回一个DECERR(解码错误)或SLVERR(从设备错误)响应。举例:这类似于你访问一个不存在的网站,服务器返回“404 Not Found”。它明确告知请求者:“你要找的东西不存在”。优点安全、清晰。

weixin_44700185的博客 675

19级暑假第七场训练赛

A: CodeForces - 1300A Input 1 1 1 Output 0 思路: 循环遍历输入,如果读入0,cnt++,sum++,如果这样sum == 0,cnt++即可 写的时候莫名写错,搞得WA2发 #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; void sol...

橘嘉禾 65

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

HDU 2019 Multi-University Training Contest 7 杭电2019多校联合训练赛 第七场 1006 Final Exam (6651)

HDU 2019 Multi-University Training Contest 7 杭电2019多校联合训练赛 第七场 1006 Final Exam (6651) 先膜拜一下牛大佬。 skr~ Problem Description Final Exam is coming! Cuber QQ has now one night to prepare for tomorrow’s ex...

BenFromHRBUST的CSDN博客 351

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

upc 个人训练赛第七场:最佳课题选择(dp)

问题 A: 本材加工 题目描述 2049年,智能机器人在各行各业中的应用已经十分普遍了,小明的运输队里就有一个,是专门用来装卸货物的。这天,他们的任务是要把N(2≤N≤50)根木材运送到家具厂去。这些木材长短不同(有擎还特别的长),为了便于运输,只好把它们切割成小段。所以,小明给机器人的任务是:把这些木材切割并装上卡车。等机器人做完这事的时候,小明一看结果,大吃一谅:原来装在车上的所有小段的木材,...

你数过天上的星星吗 1493

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

UPC2018组队训练赛第七场

题目来自ICPC 2017 Japan Tsukuba A题:Secret of Chocolate Poles 有三种巧克力,分别是厚度为1的白色巧克力,厚度为1或者k的黑色巧克力。要求把巧克力放到高度为 l 的盒子里,并且要黑白相间,底部和顶部必须都是黑色的 当l=1,ans=1;当l<k,ans=(l-1)/2+1;当l=k,ans=(l-1)/2+2;当l&gt...

weixin_30449239的博客 158

北方大学 ACM 多校训练赛 第七场 C Castle(LCA)

【题意】给你N个点,N条不同的边,Q次询问,求出u,v之间的最短路。 【分析】题意很简单,就是求最短路,但是Q次啊,暴力DIJ?当然不行,观察到这个题边的数目和点的数目是相同的,也就是说这个图是由一棵树加了一条边而形成的。而对于一棵树,如果有Q次询问最短路,那就可以用LCA来做,复杂度QlogN,但是现在加了一条边,可能会使有些点之间的路径变短。假设多加的这条边的两个端点是U,V,那么对于询问的...

weixin_34409357的博客 133

2019牛客暑期多校训练营(第七场)A String(枚举)

题目链接:https://ac.nowcoder.com/acm/contest/887#question 题目大意:给一组”01“字符串,令其分割成极可能少的字符串,并且要满足每组字符串都是”完美的“。当一个字符串比它旋转后(即将字符串后面任意i位按顺序移到前面)的字符串都要小,则它是”完美的“。 解题报告:字符串长度最长为200,直接模拟暴力枚举即可。 AC代码: ...

weixin_38168590的博客 154

Polycarp and Div 3【Codeforces Round #496 (Div. 3)【D题】】【贪心】

    应该说是今天凌晨的吧,第一次打Code Forces,懵懵懂懂的,不过感觉还是良好,做了几道签到题。难题还是没有那个水准去做......Polycarp likes numbers that are divisible by 3.He has a huge number ss. Polycarp wants to cut from it the maximum number of numb...

既然弱小,就只顾变强就是了 1094

GAME 2 3

Polycarp plays “Game 23”. Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number...

weixin_43888067的博客 295

1141A Game 23

A. Game 23 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp plays "Game 23". Initially he has a numbernnand his goal is ...

memory_qianxiao的博客 1129

Game 23

A. Game 23 time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Polycarp plays “Game 23”. Initially he has a number n and his goal is to transform i...

轻舟载君不载愁 314

java 报数游戏:有n个孩子站成一圈,从第一个孩子开始顺时针方向报数,报到m的人出列

import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class BaoShuGame { /**  报数游戏  有n个孩子站成一圈,从第一个孩子开始顺时针方向报数,报到3的人出列,下一个人继续从1报数,  直到最后剩下一个孩子为止。问剩下第几个孩子

baikaishui86的专栏 7753

序列 计蒜客

有一个整数序列,它的每个数各不相同,我们不知道它的长度是多少(即整数个数),但我们知道在某些区间中间至少有多少个整数,用(L_i,R_i,C_i)(Li​,Ri​,Ci​)来描述,表示这个整数序列中至少有C_iCi​个数来自区间[L_i,R_i][Li​,Ri​],给出若干个这样的区间,问这个整数序列的长度最少能为多少? 输入格式 第一行一个整数N\ (1\le N \le 1000)N(1≤N≤1000),表示区间个数; 接下来NN行,每行三个整数L_i,R_i,C_i\ (1\l...

wwenddy的博客 561

数字组合

小蒜有 n(1 \le n \le 20)n(1≤n≤20) 个正整数,找出其中和为 t(tt(t 也是正整数)的可能的组合方式。如: n=5,5 个数分别为 1,2,3,4,5 t=5; 那么可能的组合有 5=1+4 和 5=2+3 和 5=5 三种组合方式。 输入格式 输入的第一行是两个正整数 nn 和 tt,用空格隔开,其中 1 \le n \le 201≤n≤20, 表示正整数的个...

weixin_44606952的博客 945
下一篇: HPU算法协会公开课第一期:【基础算法1】(STL 自定义sort 前缀和差分)
xunber_
博客等级 码龄7年 1粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值