题目链接
题意给定n个辣椒和实现梦想的值,如果辣椒的年龄小于等x,则可成为菜品a,否则称为菜品b。可以对给出的辣椒交换位置,问操作后实现梦想的辣椒数量思路
-
遍历辣椒
-
若符合交换条件 则交换
-
无
#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;i num[i+1].age&&num[i].hao==1&&num[i+1].hao==0) { swap(num[i].age,num[i+1].age); } if(num[i].age x&&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<
语法题+结构体


![P7954 [COCI2014-15#6] PAPRIKA P7954 [COCI2014-15#6] PAPRIKA](http://www.mshxw.com/aiimages/31/655943.png)
