列表

详情


NC221566. MikawithCherryCake

描述

Mika wants to make some cherry cakes to eat.

The forest Mika lives can be considered as a two-dimensional Cartesian coordinate. Mika's home is located on .

In the forest, the speed of Mika and merchant is same. If you want to go from to , you will cost seconds, which is the Manhattan distance between them.

If one person if on , when he
go up for seconds, he will be at ,
go down for seconds, he will be at ,
go right for seconds, he will be at,
go left for seconds, he will be at .
Notice: may not be an integer.

Now Mika knows that there will be merchants travel through this forest. The merchant will be at at time and the diraction of each merchant will be given.

Mika will be at his home at time , when he and a merchant are at the same point, he can buy a basket of cherry, and return to the home to drop the basket, then he goes to find the second merchant and so on. You can consider the time Mika spends on buying cherries and dropping the basket at home is .

Mika is a fairy, so he can't hold two or more baskets of cherry, so he can only buy one basket of cherry and return home to drop the basket.

Now Mika wants to know the maximum baskets of cherry he can buy?

输入描述

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 \text 1 to reach \text (1,0) to buy cherry from the second merchant, also he can choose at time \text 1 to reach \text (0,1) to buy cherry from the third merchant. No matter which way Mika chooses, he will be at home at time \text 2, while the fourth merchant is at \text (3,1), Mika cannot buy cherry from him.
Or Mika can choose to buy one basket of cherry from the fourth merchant.
It can be seen that no matter which way Mika chooses, the answer will always be \text 1

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

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;
	
}

上一题