Day4上午

expect100+50+50,

In fact 100+10+0.

代码能力还有待提高,部分分应该能拿的。结果。。。力不从心啊。

T1

贪心做的不知对不对。

看来思路是对的,不知道能不能对。

暴力做超时,所以优化,计数排序。

复制代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int N=1e6+10;
int n,maxn;
int a[N];
int L,R,mid;
int check()
{    
    int sum0=0,tot=0,i=1,ans=0;
    while(!a[i])    sum0++,i++;
    for(i;i<=n;i++)
    {        
        ans=a[i];tot=a[i]-a[i-1];
        for(int j=1;j<=tot;j++)
            sum0=(sum0%2+(sum0)/2);
        sum0++;
    }
    ans=ans+(sum0%2+log2(sum0));
    return ans;
}
int main()
{
    freopen("multiset.in","r",stdin);
    freopen("multiset.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        maxn=max(maxn,a[i]);
    }
    sort(a+1,a+1+n);
    cout<<check();
    return 0;
}
first 100
复制代码

 

T2

搜的

复制代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int N=100009;
int n,m;
int h[N],nex[N*5],to[N*5],cnt;
bool vis[N*3];
int f[N],size[N];
int ans=1;
int find(int x)
{
    while(x!=f[x])
        x=f[x]=f[f[x]];
    return x;
}
bool ok[N*5];
bool dfs(int x,int last)
{
    if(x==n) return ok[last]=1;    
    for(int i=h[x];i;i=nex[i])    
    {
        
        if(ok[last])
        {
            if(abs(last-i)==1)    ans++;
        }else
        {
            
            if(ok[last]=dfs(to[i],i))        
                if(abs(last-i)==1)    ans++;
        
        }
        
    }
    return ok[last];
}
int main()
{
    freopen("road.in","r",stdin);
    freopen("road.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1,v,u;i<=m;i++)
    {
        scanf("%d%d",&v,&u);
        to[++cnt]=u,nex[cnt]=h[v],h[v]=cnt;    
    }        
    for(int i=h[1];i;i=nex[i])
    dfs(to[i],i);
    cout<<ans<<endl;
    return 0;
}
first
复制代码

 题解用的变态的二分,

有人增量法。

 

 

T3

搜的

最高分10分。。。。。。

复制代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int N=1020;
int T,n,maxn;
int  a[N],ans;
void dfs(int x,int tot)
{
    ans=max(ans,tot);
    if(x-1==maxn)        
            return ;    
    for(int i=1;i<=n;i++)
    if(a[i]>x-1)
    {
        a[i]--;
        if(a[i]==x)
        dfs(x+1,tot+1);
        else dfs(x+1,tot);
        a[i]++;
    }
    return ;
}
int main()
{
    freopen("cs.in","r",stdin);
    freopen("cs.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            maxn=max(maxn,a[i]);
        }
        
        dfs(1,0);
        printf("%d\n",ans);
    }
    return 0;
}
first
复制代码

 

posted @   浪矢-CL  阅读(257)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示