文博2

文博模拟题2

day1t1

1.不用把\(n*m-n-m\)减到0,减够\(k\)即可。
2.若\(n\)\(m\)其中有一个为1,答案为\(-1\),不特判会\(RE\),不知道为啥。
3.队列里可能会有重复元素,要去一下重。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define LL long long 
using namespace std;
priority_queue<LL> q;
LL n,m,k,ansp,last,cnt;
void cutn(LL u)
{
    while(u>n)
    {
        u-=n;
        q.push(u),++cnt;
    }
    return ;
}
void cutm(LL u)
{
    while(u>m)
    {
        u-=m;
        q.push(u);
    }
    return ;
}
int main()
{
    freopen("day1t1.in","r",stdin);
    freopen("day1t1.out","w",stdout);
    scanf("%lld%lld%lld",&n,&m,&k);
    if(n==1||m==1) { printf("-1\n"); return 0;}
    ansp=n*m-n-m;
//  q.push(ansp);
    for(int i=0;i<=500;i++)
     for(int j=0;j<=500;j++)
      if((ansp-i*n-j*m)>0) q.push(ansp-i*n-j*m);
//  cutn(ansp); cutm(ansp);
//  ansp-=n;
//  while(ansp>m)
//  {
//      cutm(ansp);
//      ansp-=n;
//  }
//  while(ansp>0)
//  {
//      ansp-=n;
//      q.push(ansp);
//      q.push(ansp+n-m);
//  }
    for(int i=1;i<k;i++)
    {
//      cout<<q.top()<<"*";
        if(q.top()==last) ++i;
        if(q.empty()) { printf("-1\n"); return 0;}
        q.pop();
    }
    ansp=q.top();
    printf("%lld\n",ansp);
    return 0;
}

80days

思路:(哦,最先判断一下是否为-1,如果所有的合加起来,再加\(c\)小于0的话就是\(-1\)了)开一个数组记录一下前缀和,再开两个数组记录一下前缀最小值和后缀最小值。从小到大判断以\(i\)为起点是否可行,可行的话输出,结束。

如果第\(i\)个点作为起点可行,那么满足(\(+c\)省略):后缀最小值减去前缀和大于0并且前缀最小值加上后面所有数的和大于0。

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
const int N = 1e6+5;
const LL inf = 1e15+9;
LL T,n,a[N],b[N],c,sum;
LL cnt[N],pre[N],suf[N];
bool flag;
inline LL read()
{
    char c=getchar();
    LL ans=0,w=1;
    while((c<'0'||c>'9')&&c!='-') c=getchar();
    if(c=='-') { w=-1; c=getchar(); }
    while(c>='0'&&c<='9')
    { ans=ans*10+c-'0'; c=getchar(); }
    return ans*w;
}
int main()
{
    T=read();
    while(T--)
    {
        flag=0;
        n=read(); c=read();
        sum=0; cnt[0]=0;
        pre[0]=inf; suf[n+1]=inf;
        for(int i=1;i<=n;i++)
         a[i]=read();
        for(int i=1;i<=n;i++)
        {
            b[i]=read();
            a[i]-=b[i]; sum+=a[i];
            cnt[i]=cnt[i-1]+a[i];
            pre[i]=min(pre[i-1],cnt[i]);
        }
        for(int i=n;i>=1;i--)
         suf[i]=min(suf[i+1],cnt[i]);
        if(sum+c<0) { printf("-1\n"); continue; }
        if(suf[1]+c>0) printf("1 ");
        for(int i=2;i<=n;i++)
        {
            if(a[i]+c<0||flag) continue;
            if(suf[i]+c>=cnt[i-1]&&pre[i-1]+sum-cnt[i-1]+c>=0)
             printf("%d ",i),flag=1;
        }
    }
    return 0;
} 

转载于:https://www.cnblogs.com/karryW/p/10993935.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值