【火腿赛区现场赛Problem J】妈妈说阿迪王比耐克牛-Dressing

本文解析了一道ACM/ICPC亚洲区竞赛题目的解题思路及代码实现,强调通过理解题目描述来简化问题求解过程。文章包含关键代码段,并通过实例演示如何避免超时错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FROM:2012-10-28 ACM/ICPC ASIA JinHua Area,Problem J. 点击打开链接

这个题看着虎,其实还是很水。。。。但因为阅读理解,坑了一些时间。难得这么大的比赛有两道不用脑子的水题。。。

描述上亮点颇多:

1、Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike.(囧RZ)

2、Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.(这说明只有两种情况 没有clothes和shoes一起不和谐的情况)

3、For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.(注意200000,这说明不用按部就班的模拟,否则TLE)

明白了这些,AC便指日可待了……

1TLE(200000纯属坑爹的) 1WA(数组初始化开错了) 1AC:

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int INF=1005;
int clothes[INF],pants[INF],shoes[INF];

int main()
{
	int yi,ku,xie;
	while(cin>>yi>>ku>>xie && (yi!=0 || ku!=0 || xie!=0))
	{
		for(int i=0;i<=INF;i++)
		{
			clothes[i]=0;
			pants[i]=0;
			shoes[i]=0;
		}
		int hexienum,result=0;
		cin>>hexienum;
		if(hexienum==0)
		{
			cout<<yi*ku*xie<<endl;
			continue;
		}
		else
		{
			for(int i=0;i<hexienum;i++)
			{
				
			
			string opa,opb;
			int buhexie1,buhexie2;
			cin>>opa>>buhexie1>>opb>>buhexie2;
			if(opa=="clothes" || opb=="clothes")
			{
				clothes[buhexie2]++;
			}
			if(opb=="shoes" || opa== "shoes")
			{
				shoes[buhexie1]++;
			}
			
			}
			
			
			for(int i=1;i<=ku;i++)
			{
				result+=(xie-shoes[i])*(yi-clothes[i]);
			}
			
			cout<<result<<endl;
		}
		
		
		
		
		
		
	}
	
	
	
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值