NC221566. MikawithCherryCake
描述
输入描述
The first line is an integer , repersenting the number of merchant.
The next lines are Three integers ,representing the position of the merchant and the direction the merchant travels.
If , the merchant is moving up.
If , the merchant is moving down.
If , the merchant is moving right.
If , the merchant is moving left.
输出描述
One integer, the maximum baskets of cherry Mika can buy.
示例1
输入:
4 1 1 1 1 1 2 1 1 4 3 3 2
输出:
1
说明:
Mika can't buy cherry from the first merchant, he can choose at time to reach to buy cherry from the second merchant, also he can choose at time to reach to buy cherry from the third merchant. No matter which way Mika chooses, he will be at home at time , while the fourth merchant is at , Mika cannot buy cherry from him.C++(clang++11) 解法, 执行用时: 10ms, 内存消耗: 508K, 提交时间: 2021-05-08 20:48:58
#include<bits/stdc++.h> using namespace std; vector<pair<int,int> > v; int main(){ int t; cin>>t; while(t--){ int a,b,c; cin>>a>>b>>c; if(c==1||c==3) continue; if(c==2) v.push_back(make_pair(a+b, a)); if(c==4) v.push_back(make_pair(a+b, b)); } int ans = 0; int now = 0; sort(v.begin(),v.end()); for(int i=0;i<v.size();i++){ if(v[i].second*2+now<=v[i].first){ ans++; now=v[i].first; } } cout<<ans<<endl; return 0; }