2022icpc昆明

https://ac.nowcoder.com/acm/contest/32708

1.King of Gamers

0 0 \frac{0}{0} 00每次赢分子分母+1,输分母+1,当前值> a b \frac{a}{b} ba必输,否则必赢。
设赢了 x x x次,上述易知最后分母为 n n n,则 x n > a b \frac{x}{n}>\frac{a}{b} nx>ba,即 x > a ∗ n b x>\frac{a*n}{b} x>ban。细节特判最后答案合不合法+1即可。

#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        ll n,a,b;
        cin>>n>>a>>b;
        ll ans=n*a/b;
        if(ans*b<=a*(n-1))ans++;
        cout<<ans<<'\n';
    }
}

2.Divisions

打表找规律注意0

#include <bits/stdc++.h>
using namespace std;
int fan(vector<int>a){
    int ans=0;
    for(int i=0;i<(1<<a.size());i++){
        vector<int>u,v;
        for(int j=0;j<a.size();j++){
            if(i>>j&1)u.push_back(a[j]);
            else v.push_back(a[j]);
        }
        reverse(v.begin(),v.end());
        ans+=is_sorted(u.begin(),u.end())&&is_sorted(v.begin(),v.end());
    }
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==0){
        cout<<"4\n50 100 1 25";
    }else if(n==1){
        cout<<"6\n1 1 4 5 1 4";
    }else{
        vector<int>res;
        int la=1,ans=1,cnt=0;
        while(ans<n){
            if(ans+(1ll<<cnt)<=n){
                ans+=(1ll<<cnt);
                cnt++;
                res.push_back(la);
            }else{
                la++;
                cnt=0;
            }
        }
        cout<<res.size()<<'\n';
        for(auto &t:res){
            cout<<t<<" ";
        }
    }
}

3.Find the Maximum

非常经典的二分答案。
∑ u ∈ V ( − x 2 + b u x ) ∣ V ∣ = − x 2 + ∑ u ∈ V b u ∣ V ∣ x \frac{\sum_{u\in{V}}(-x^2+b_ux)}{|V|}=-x^2+\frac{\sum_{u\in V}b_u}{|V|}x VuV(x2+bux)=x2+VuVbux
r e s = ∑ u ∈ V b u ∣ V ∣ res=\frac{\sum_{u\in V}b_u}{|V|} res=VuVbu由基本不等式易知答案为 r e s 2 4 \frac{res^2}{4} 4res2

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e5+10 ;
constexpr double inf = 1e14 ; 
double val[N];
double dp[N],ans[N];
vector<int>g[N];
int fa[N];
template<class Tp=int>
Tp read(){
    char ch=getchar();bool f=1;Tp x=0;
    while(!isdigit(ch)){
        if(ch=='-')f=false;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=(x<<3)+(x<<1)+(ch^48);
        ch=getchar();
    }
    return f?x:-x;
}
template<class Tp=int>
void print(Tp n){
    if(n>9)print(n/10);
    putchar(n%10|'0');
}
vector<int>uu;
void dfs(int x,int f){
    fa[x]=f;
    for(auto &t:g[x]){
        if(t==f)continue;
        dfs(t,x);
    }
    uu.push_back(x);
}
bool check(double now){
    for(auto &t:uu){
        dp[t]=val[t]-now;
        ans[t]=-1e100;
        for(auto &x:g[t])if(x!=fa[t]){
            ans[t]=max(ans[t],dp[x]+dp[t]);
            dp[t]=max(dp[t],dp[x]+val[t]-now);
            ans[t]=max(ans[t],ans[x]);
        }
    }
    return ans[1]>=0;
}
int main()
{
    int n=read();
    for(int i=1;i<=n;i++){
        val[i]=read();
    }
    for(int i=1,x,y;i<n;i++){
        x=read(),y=read();
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,0);
    double ans;
    double l=-1e5,r=1e5;
    for(int i=1;i<=50;i++){
        double mid=(l+r)/2.0;
        if(check(mid))l=mid;
        else r=mid;
    }
    ans=l;
    for(int i=1;i<=n;i++)val[i]=-val[i];
    l=-1e5,r=1e5;
    for(int i=1;i<=50;i++){
        double mid=(l+r)/2.0;
        if(check(mid))l=mid;
        else r=mid;
    }
    ans=max(ans,l);
    cout<<fixed<<setprecision(6);
    cout<<ans*ans/4.0;
}

持续更新中…

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倾海、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值