当前位置:网站首页>Provincial competition exercise 2 -- the 8th Fujian college student programming competition & supplementary questions
Provincial competition exercise 2 -- the 8th Fujian college student programming competition & supplementary questions
2022-04-22 04:14:00 【Jinze_ L】
Accept: 160 Submit: 431
Time Limit: 1000 mSec Memory Limit : 262144 KB
Problem Description
Yinyangshi is a famous RPG game on mobile phones.
Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Each time you can only draw one card, all the cards appear randomly with same probability 1/n. Kim can get 1 coin each day. Suppose Kim has 0 coin and no cards on day 0. Every W days, Kim can draw a card with W coins. In this problem ,we define W=(n-1)!.
Now Kim wants to know the expected days he can collect all the n kinds of cards.
Input
The first line an integer T(1 ≤ T ≤ 10). There are T test cases.
The next T lines, each line an integer n. (1≤n≤3000)
Output
For each n, output the expected days to collect all the n kinds of cards, rounded to one decimal place.
Sample Input
Sample Output
Let's assume that there is already a A card , If we want to get the second a+1 Zhang , The probability of our winning it is obviously (n-a)/n, The reciprocal of probability is its expectation , So his expectation is n/(n-a), If you add up, the total expectation is n(1+1/2+1/3+...+1/n), And then multiplied by the (n-1)!, The final formula is n!(1+1/2+1/3+...+1/n). Try to avoid two different types of large number operations .
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class YYS {
static BigInteger jie(int x)
{
BigInteger sum= BigInteger.ONE;
for(int i=1;i<=x;i++)
{
BigInteger z= BigInteger.valueOf(i);
sum=sum.multiply(z);
}
return sum;
}
/*static BigDecimal qi(int x)
{
BigDecimal sum =BigDecimal.valueOf(0);
for(double i=1;i<=x;i++)
{
double z=1/i;
sum=sum.add(BigDecimal.valueOf(z));
}
return sum.multiply(BigDecimal.valueOf(x));
}
*/
public static void main(String[] args) {
int t=0;;
Scanner cin=new Scanner(System.in);
t=cin.nextInt();
for(int k=0;k<t;k++)
{
int n;
n=cin.nextInt();
BigInteger ans=BigInteger.ZERO;
BigInteger sum1=jie(n);
for(int i=1;i<=n;i++){
ans=ans.add(sum1.divide(BigInteger.valueOf(i)));
}
System.out.println(ans+".0");
/* BigDecimal sum1=jie(n-1);
BigDecimal sum2=qi(n);
BigDecimal aaa=sum1.multiply(sum2);
System.out.println(String.format("%.1f", aaa));*/
}
}
}
Accept: 119 Submit: 635
Time Limit: 1000 mSec Memory Limit : 262144 KB
Problem Description
This is a very easy problem.
ACMeow loves GTX1920. Now he has m RMB, but no GTX1920s. In the next n days, the unit price of GTX1920 in the ith day is Ci RMB. In other words, in the ith day, he can buy one GTX1920 with Ci RMB, or sell one GTX1920 to gain Ci RMB. He can buy or sell as many times as he wants in one day, but make sure that he has enough money for buying or enough GTX1920 for selling.
Now he wants to know, how many RMB can he get after the n days. Could you please help him?
It’s really easy, yeah?
Input
First line contains an integer T(1 ≤ T ≤20), represents there are T test cases.
For each test case: first line contains two integers n(1 ≤ n ≤2000) and m(0 ≤ m ≤1000000000). Following n integers in one line, the ith integer represents Ci(1 ≤ Ci ≤1000000000).
Output
For each test case, output "Case #X: Y" in a line (without quotes), where X is the case number starting from 1, and Y is the maximum number of RMB he can get mod 1000000007.
Sample Input
Sample Output
The question :
business GTX1920, We know that every piece in the future GTX1920 The price of , Ask about the biggest profit after trading
- Buy as much as you can every time you buy , Sell it all every time
- Buy in every local price Valley , Then sell at the top of the first local price
- The final funds will be large , exceed long long The scope of the , But the intermediate result cannot be modeled , Otherwise, you can't calculate the next purchase GTX1920 The number of , So use BigInteger To calculate
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int T;
int n,m;
int[] c = new int[2005];
T=cin.nextInt();
BigInteger ans,mod=BigInteger.valueOf(1000000007);
for(int xx=1;xx<=T;++xx){
n=cin.nextInt();
m=cin.nextInt();
ans=BigInteger.valueOf(m);
for(int j=0;j<n;++j) {
c[j]=cin.nextInt();
}
int i,j,k;
for(i=0;i<n;) {
j=i;
while(j<n-1&&c[j+1]<=c[j])++j;
if(j==n-1)break;
k=j;
while(k<n-1&&c[k+1]>c[k])++k;
BigInteger res=ans.mod(BigInteger.valueOf(c[j]));
BigInteger buy=ans.divide(BigInteger.valueOf(c[j]));
buy=buy.multiply(BigInteger.valueOf(c[k]));
ans=res.add(buy);
i=k+1;
}
System.out.println("Case #"+xx+": "+ans.mod(mod));
}
}
}
版权声明
本文为[Jinze_ L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211048484346.html
边栏推荐
- Where is the whole house intelligence that Huawei, Haier Zhijia and Xiaomi are all doing?
- Tensorflow error: returned a result with an error set solution
- Leetcode1615. Maximum network rank (medium)
- Determination of bipartite graph by coloring method
- 均线双边对锁策略原理
- Stc8a8k64d4 (51 Series MCU) printf printing data abnormal problem
- 插一个数到排好序的数组中(冒泡+rand函数)
- Autodesk genuine Service 2020 Supprimer
- MySQL Download
- The United States raised interest rates and devalued the RMB, but such products ushered in a honeymoon period
猜你喜欢

交通行业提升数据利用效率的核心是做好数据交换与共享

Pytorch uses profiler to analyze the performance of the model

LeetCode 63. 不同路径 II

Data cleaning chapter05 | data grouping and data imbalance

How to generate PCB real-time snapshot in 3D in Ad

SQL statements used occasionally

. net debugging: use visual studio to debug dump files

sqlilabs(25a-26)

Registration process of New Zealand company and materials required

02-SparkSQL
随机推荐
调用函数时,关于传参那些事~
交通行业提升数据利用效率的核心是做好数据交换与共享
Ncurses installation package and PKG config information
OpenSCA版本升级 | OpenSCA v1.0.4版本发布
02 - sparksql
03-DataFrame & Column
为啥sqlmap能跑出库表跑不出字段
Dynamic | hanging mirror safety R & D management system has passed CMMI3 international certification
[network experiment] / host / router / switch / gateway / Routing Protocol / rip + OSPF / DHCP
Opensca version upgrade | opensca v1.0 Release of version 0.4
05-Aggregation
Mysql中的Decimal类型是什么?
How do CDN acceleration and CDN defense operate to the server?
jeesite导出Excel
[Ext JS ] 7.25.1 Form或者面板自动定位到错误的输入框
使用 nohup 命令将程序挂载在后台执行
Ronglian Qimo empowers enterprises with intelligent services and redefines the value of customer service
Jeesite export Excel
. net 20th anniversary learning challenge Net mobile application
Data mining series (2)_ The data mining plug-in of Excel connects to SQL server