洛谷试炼场 - 关卡2-1 - 简单的模拟 - (Undone)

最近这段时间感冒外加一些乱七八糟的事情,导致脑子严重僵化……只好刷刷基础(水)题巩固巩固基础(混混题数)。


P1003 铺地毯

题目链接:https://www.luogu.org/problemnew/show/P1003

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int n,x,y;
int a[maxn],b[maxn],g[maxn],k[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d%d%d",&a[i],&b[i],&g[i],&k[i]);
    scanf("%d%d",&x,&y);
    int ans=-1;
    for(int i=n;i>=1;i--)
    {
        if(a[i]<=x && b[i]<=y && a[i]+g[i]>=x && b[i]+k[i]>=y)
        {
            ans=i;
            break;
        }
    }
    printf("%d\n",ans);
}

P1067 多项式输出

题目链接:https://www.luogu.org/problemnew/show/P1067

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
    while(cin>>n)
    {
        for(int i=n,c;i>=0;i--)
        {
            scanf("%d",&c);
            if(c==0) continue;
            else if(c>0)
            {
                if(i<n) printf("+");
                if(c>1) printf("%d",c);

                if(i>1) printf("x^%d",i);
                else if(i==1) printf("x");
                else if(c==1) printf("1");
            }
            else
            {
                printf("-");
                if(-c>1) printf("%d",-c);

                if(i>1) printf("x^%d",i);
                else if(i==1) printf("x");
                else if(-c==1) printf("1");
            }
        }
        printf("\n");
    }
}

P1540 机器翻译

题目链接:https://www.luogu.org/problemnew/show/P1540

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
int m,n;
int vis[maxn];
queue<int> Q;
inline void Push(int x)
{
    if(Q.size()>=m)
    {
        vis[Q.front()]=0;
        Q.pop();
    }
    vis[x]=1;
    Q.push(x);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin>>m>>n;
    int ans=0;
    for(int i=1,x;i<=n;i++)
    {
        cin>>x;
        if(!vis[x]) Push(x), ans++;
    }
    cout<<ans<<endl;
}

猜你喜欢

转载自www.cnblogs.com/dilthey/p/9983272.html
今日推荐