A-Dogs'Candies


题解:

method1:迭代器

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<algorithm>
#include<stack>
#include<list>
#include<map>
#define ERROR -1
#define TURE 1
#define OK 1
#define INF -99999999
typedef long long ll;

using namespace std;
list<pair<ll,ll> >p;
list<pair<ll,ll> >::iterator it;
ll n,c,u,v;
ll ans;
int main()
{
   while(cin>>n&&n)
   {
    	while(n--)
    	{
         cin>>c>>u>>v;
         pair<ll,ll>q(u,v); 
		 if(c==1)
		 {
		  
	      p.push_back(q);	 	
	     }
	     else if(c==-1)
		 {
		   for(it=p.begin();it!=p.end();it++)
		   {
		   	if(*it==q)
		   	{
		   	 p.erase(it);
		   	 break;
			}
		   }	
		 }
		 else
		 {
		 	ans=INF;
		 	for(it=p.begin();it!=p.end();it++)
		 	{
		 	  ans=max(ans,it->first*u+it->second*v);	
			}
			cout<<ans<<endl; 
		 	
		 } 
	     
		}
		p.clear();
   }

} 

method2:结构体

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<map>
#define ERROR -1
#define TURE 1
#define OK 1
#define INF -99999999
using namespace std;
struct DogC{
	int kind;
	long long x,y;
}p[50005];
int k=0,c,u,v;
long long ans;
int main()
{
  int n;
  while(cin>>n&&n)
  {
    int t=n;
    k=0;
	while(t--)
	{
	  cin>>c>>u>>v;
	  if(c==1)
	  {
	    p[k].x=u;
		p[k++].y=v; 	
	  }
	  else if(c==-1)
	  {
	  	for(int i=0;i<k;i++)
		  {
		    if(p[i].x==u&&p[i].y==v)
			{
		      p[i].x=p[i].y=0;
			}	
		  } 
	  }
	  else
	  {
	  	ans=INF;
	    for(int i=0;i<k;++i)
		{
		  long long res=p[i].x*u+p[i].y*v;
		  if(res>ans)
		  ans=res;
		}  
		cout<<ans<<endl;	
	  }	
	}  	
  }	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值