记录编号 |
121976 |
评测结果 |
AAAAAA |
题目名称 |
[POI 1997] 阿里巴巴 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.021 s |
提交时间 |
2014-09-22 08:58:46 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
struct trades
{
int g1,s1,c1,g2,s2,c2;
friend inline istream &operator >>(istream &p,trades &rd)
{
p>>rd.g1>>rd.s1>>rd.c1>>rd.g2>>rd.s2>>rd.c2;
return p;
}
};
struct node
{
int g,s,c;
node (int g=0,int s=0,int c=0):g(g),s(s),c(c){}
node trade(const trades &rhs)
{
node res;
res.g=g-rhs.g1+rhs.g2;
res.s=s-rhs.s1+rhs.s2;
res.c=c-rhs.c1+rhs.c2;
return res;
}
bool operator <(const node &rhs) const
{
if (g!=rhs.g)
return g<rhs.g;
if (s!=rhs.s)
return s<rhs.s;
if (c!=rhs.c)
return c<rhs.c;
return false;
}
};
//==============var declaration=================
const int MAXN=20;
trades Trade[MAXN];
int t,m,sg,ss,sc,eg,es,ec;
set <node> Exist;
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="ali";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
cin>>t;
while (t--)
{
cin>>sg>>ss>>sc>>eg>>es>>ec>>m;
Exist.clear();
For(i,1,m)
cin>>Trade[i];
queue <node> Q;
queue <int> T;
Q.push(node (sg,ss,sc));
T.push(0);
bool suc=false;
while (!Q.empty())
{
node now=Q.front();Q.pop();
int Time=T.front();T.pop();
if (Exist.count(now))
continue;
Exist.insert(now);
if (now.s>=es&&now.g>=eg&&now.c>=ec)
{
printf("%d\n",Time);
suc=true;
break;
}
if (Time>=200) break;
For(i,1,m)
if (now.s>=Trade[i].s1&&now.g>=Trade[i].g1&&now.c>=Trade[i].c1)
{
node push=now.trade(Trade[i]);
Q.push(push);
T.push(Time+1);
}
}
if (!suc)
printf("NIE\n");
}
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================