首页 > 其他分享 >13.【初三奥赛模拟测试2】

13.【初三奥赛模拟测试2】

时间:2024-03-15 18:44:56浏览次数:23  
标签:13 read long int panzer signed 奥赛 初三 define

  • 估计也打不了多少 \(qwq\)

\(\Huge终于不垫底了。qwq\)

初三奥赛模拟测试2

T1

题解

  • 一道概率期望。
  • 一般都是从 \(n\) 开始递推到 \(0\) 。
  • 假设我们现在有 \(i\) 种枪,那么期望次数

\[\large f_i=f_{i+1}+\frac n{n-i} \]

  • 因为当前有 \(i\) 种可能买到已经买过的枪, \(n-i\) 种可能买到未买过的枪。直接加上即可。
  • 期望的价钱就是

\[\large g_i=g_{i+1}+\frac n{n-i}\times f_{i} \]

  • 假如每把枪的价格都是 \(1\) ,显然结果就是期望次数。
  • 由于每次购买价格需要 \(+1\) , 因此也很容易就能得出买到下一把枪的期望价钱就是买到这把枪的期望次数,直接乘起来即可。

代码

#include<bits/stdc++.h>
#define int long long
#define N (1000010)
#define I i
#define J j
#define raed read
#define reaD read
#define reAD read
#define rEAD read
#define READ read
#define REAd read
#define REad read
#define Read read
#define Reda read
#define redA read
#define reDA read
#define redA read
#define itn signed
#define Itn signed
#define ITN signed
#define Int signed
#define INT signed
#define foR for
#define fot for
#define foT for
#define sort stable_sort
using namespace std;
namespace IO
{
    #define ll long long
    const int MAX=1<<6;
    char buf[MAX],*p1=buf,*p2=buf;
    char obuf[MAX],*o=obuf;
    #define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<6,stdin),p1==p2)?EOF:*p1++)
    //template<typename T>
    //inline T read()
    inline int read()
    {
        int x=0;bool f=1;
        char c=gc();
        for(;c<48||c>57;c=gc())if(c=='-')f=0;
        for(;c>=48&&c<=57;c=gc())x=(x<<3)+(x<<1)+(c^48);
        return f?x:~x+1;
    }
    void print(ll x){if(x>9)print(x/10);*o++=(x%10)+'0';}
    void pit(ll x){if(x<0)*o++='-',x=~x+1;print(x);}
    void write(ll x,char ed){pit(x);*o++=ed;}
    void flush(){fwrite(obuf,o-obuf,1,stdout);}
    #undef ll
}
using IO::read;using IO::write;using IO::flush;using std::complex;
inline int min(int x,int y){return y&((y-x)>>31)|x&(~(y-x)>>31);}
inline int max(int x,int y){return x&((y-x)>>31)|y&(~(y-x)>>31);}
inline void swap(int &x,int &y){x^=y^=x^=y;}
long long n,m;
void init_set()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
}
int tot,t,x,y;
int furina,fucaros;
double panzer[10010],nahida[10010];
signed main()
{
    init_set();
    n=read();
    for(int i(n-1);i>=0;--i)
    {
        nahida[i]=1.0*nahida[i+1]+1.0*n/(n-i);
        panzer[i]=1.0*panzer[i+1]+nahida[i]*1.0*n/(n-i);
    }
    printf("%.2f\n",panzer[0]);
    flush();
    return 0;
}
  • 由于递推时只需要当前以及上一个状态,因此用四个变量即可替代。
#include<bits/stdc++.h>
#define int long long
#define N (1000010)
#define I i
#define J j
#define raed read
#define reaD read
#define reAD read
#define rEAD read
#define READ read
#define REAd read
#define REad read
#define Read read
#define Reda read
#define redA read
#define reDA read
#define redA read
#define itn signed
#define Itn signed
#define ITN signed
#define Int signed
#define INT signed
#define foR for
#define fot for
#define foT for
#define sort stable_sort
using namespace std;
namespace IO
{
    #define ll long long
    const int MAX=1<<6;
    char buf[MAX],*p1=buf,*p2=buf;
    char obuf[MAX],*o=obuf;
    #define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<6,stdin),p1==p2)?EOF:*p1++)
    //template<typename T>
    //inline T read()
    inline int read()
    {
        int x=0;bool f=1;
        char c=gc();
        for(;c<48||c>57;c=gc())if(c=='-')f=0;
        for(;c>=48&&c<=57;c=gc())x=(x<<3)+(x<<1)+(c^48);
        return f?x:~x+1;
    }
    void print(ll x){if(x>9)print(x/10);*o++=(x%10)+'0';}
    void pit(ll x){if(x<0)*o++='-',x=~x+1;print(x);}
    void write(ll x,char ed){pit(x);*o++=ed;}
    void flush(){fwrite(obuf,o-obuf,1,stdout);}
    #undef ll
}
using IO::read;using IO::write;using IO::flush;using std::complex;
inline int min(int x,int y){return y&((y-x)>>31)|x&(~(y-x)>>31);}
inline int max(int x,int y){return x&((y-x)>>31)|y&(~(y-x)>>31);}
inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
long long n,m;
void init_set()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
}
int tot,t,x,y;
int furina,fucaros;
double panzer,sumeru,nahida,fontaine;
signed main()
{
    init_set();
    n=read();
    for(int i(n-1);i>=0;--i)
        nahida=fontaine+1.0*n/(n-i),
        panzer=1.0*sumeru+nahida*n/(n-i),
        fontaine=nahida,sumeru=panzer;
    printf("%.2f\n",panzer);
    flush();
    return 0;
}
  • 最后发现竟然能优化成这样!
for(int i(n-1);i>=0;--i)
    panzer+=(nahida+=1.0*n/(n-i))*n/(n-i);
printf("%.2f\n",panzer);
  • 直接用两个变量不断更新就可以了 \(qwq\) 。

\(\Huge因为根本没打。qwq\)

标签:13,read,long,int,panzer,signed,奥赛,初三,define
From: https://www.cnblogs.com/minecraft666/p/18074021

相关文章

  • 13. 罗马数字转整数c
    intromanToInt(char*s){intn=strlen(s);intc[26];c['I'-'A']=1;c['V'-'A']=5;c['X'-'A']=10;c['L'-'A']=50;c['C'-'A']=100;......
  • 卡码java基础课 | 13.链表的基础操作I
    学习内容:链表基础重点归纳:见例题例题:解:点击查看代码importjava.util.Scanner;//定义链表classLinkedList{//定义链表中的链表节点publicstaticclassNode{intdata;//数据Nodenext;//指针publicNode(intdata){/......
  • 初三奥赛模拟测试2
    前言比赛链接——南昌起义。这辈子第一次\(rk~1\)。\(T1:\)概率期望,本来没学过,现学的(蓝书没看懂,还是网上的博客好理解),然后发现毕竟\(T1\)没那么难,知道概率期望是啥还是能做的。\(T2:\)本来看\(T1\)概率期望想先开\(T2\)的,但是发现不会就去学概率期望了,后来发......
  • 代码随想录算法训练营第四十七天| ● 198.打家劫舍 ● 213.打家劫舍II ● 337.打家
    打家劫舍 题目链接:198.打家劫舍-力扣(LeetCode)思路:每一家的最大收益来源只有两个,一个是这家不偷,那么最大收益等于从上一家出来的最大收益,另一个是偷这一个家,因此最大收益等于从上上一家出来的最大收益加这一家的收益。classSolution{public:introb(vector<int>&nu......
  • 代码随想录算法训练营第四十七天 | 337.打家劫舍III,213.打家劫舍II ,198.打家劫舍
     198.打家劫舍 已解答中等 相关标签相关企业 你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。给定一......
  • Directory Opus 13.4 Crack
    DirectoryOpus是一个具有许多不同功能的文件管理器。该程序旨在取代Windows资源管理器,从而使文件处理更加方便并提供许多新功能。该程序提供了方便的文件管理功能,支持处理档案、访问FTP、处理图形和音乐文件。该程序具有多种设置和附加功能。DirectoryOpus和其他文件管理......
  • Django ORM 常用的13个方法
    DjangoORM常用的13个方法介绍一个可以以py脚本方式运行ORM操作的方法:可在项目内新建个py文件,复制项目内manage.py文件中的以下代码:if__name__=="__main__":os.environ.setdefault("DJANGO_SETTINGS_MODULE","ORM1.settings")importdjango#手动添加......
  • 信息学奥赛一本通:1146:判断字符串是否为回文
    【题目描述】输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。【输入】输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。【输出】如果字符串是回文,输出yes;否则,输出no。【输入样例】abcdedcba【输出样例】yes【参考程序......
  • 代码随想录算法训练营第day46|139.单词拆分 、多重背包
    目录139.单词拆分多重背包 139.单词拆分力扣题目链接(opensnewwindow)给定一个非空字符串s和一个包含非空单词的列表wordDict,判定 s是否可以被空格拆分为一个或多个在字典中出现的单词。说明:拆分时可以重复使用字典中的单词。你可以假设字典中没有重复的单......
  • 代码随想录算法训练营第四十六天| 139.单词拆分 多重背包 背包问题总结篇!
    单词拆分 题目链接:139.单词拆分-力扣(LeetCode)思路:竟然真能转化为背包问题。classSolution{public:boolwordBreak(strings,vector<string>&wordDict){unordered_set<string>t(wordDict.begin(),wordDict.end());vector<bool>dp(s.size()+......