栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

P7954 [COCI2014-15#6] PAPRIKA

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

P7954 [COCI2014-15#6] PAPRIKA

题目

题目链接

题意
给定n个辣椒和实现梦想的值,如果辣椒的年龄小于等x,则可成为菜品a,否则称为菜品b。可以对给出的辣椒交换位置,问操作后实现梦想的辣椒数量
思路
  1. 遍历辣椒
  2. 若符合交换条件 则交换
坑点
代码
#include
#define endl 'n' 
#define int long long
using namespace std;
const int N = 2e5+10;
typedef long long ll;
struct name{
    int age;
    int hao;
}num[N];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //n个辣椒
    //不超过x的做a,超过做b
    //辣椒想成为a或b
    //实现辣椒梦想
    int n,x;
    cin>>n>>x;
    int ans=0;
    for(int i=0;i>num[i].age;
        cin>>num[i].hao;
    }
    for(int i=0;inum[i+1].age&&num[i].hao==1&&num[i+1].hao==0)
        {
            swap(num[i].age,num[i+1].age);
        }
        if(num[i].agex&&num[i].hao==0)
        {
            ans++;
        }
    }
    if(num[n-1].age<=x&&num[n-1].hao==1)
    {
        ans++;
    }
    if(num[n-1].age>x&&num[n-1].hao==0)
    {
        ans++;
    }
    cout<
总结
语法题+结构体
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/655943.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号