This is the code in my harddisk,
I can't remenber who wrote it:
-------------------------------------------------------------
#include <iostream>
using namespace std;
#define Rep(i,n) for (int i(0),_n(n); i<_n; ++i)
struct Flavor{
int X;
char Y;
};
struct Customer{
int T;
Flavor* F;
Customer() {
F = NULL;
}
~Customer() {
if(NULL!=F) {
delete[] F;
F = NULL;
}
}
void Init(int t) {
T = t;
F = new Flavor[T];
}
void SetFlavor(int i, int X, int Y) {
F[i].X = X;
F[i].Y = Y;
}
int GetFlavorX(int i) {
return F[i].X;
}
int GetFlavorY(int i) {
return F[i].Y;
}
bool IsSatisfied() {
return T==0;
}
void Satisfy() {
T=0;
if(NULL!=F) {
delete[] F;
F = NULL;
}
}
bool IsSatisfing(int i, int *f) {
return f[F[i].X]==F[i].Y;
}
void SetMalted(int i, int *f) {
f[F[i].X] = 1;
}
};
int main()
{
int C;
FILE *fp = fopen("A.out", "w");
scanf("%d", &C);
Rep(c, C) {
int N;
scanf("%d", &N);
int* f = new int[N+1];
Rep(i ,N+1) {
f[i]=0;
}
int M;
scanf("%d", &M);
Customer* customer = new Customer[M];
Rep(m, M) {
int T;
scanf("%d", &T);
customer[m].Init(T);
Rep(t, T) {
int X, Y;
scanf("%d%d", &X,&Y);
customer[m].SetFlavor(t,X,Y);
}
}
bool findSolution = true;
int m = 0;
while(m<M) {
if(customer[m].IsSatisfied()) {
m++;
continue;
}
bool malted = false;
int idx;
bool satisfied = false;
Rep(t, customer[m].T) {
if(customer[m].GetFlavorY(t)==1) {
malted = true;
idx = t;
}
if(customer[m].IsSatisfing(t,f)) {
satisfied = true;
}
}
if(!satisfied) {
if(malted) {
customer[m].SetMalted(idx,f);
customer[m].Satisfy();
m=0;
} else {
findSolution = false;
break;
}
} else {
m++;
}
}
fprintf(fp,"Case #%d: ", c+1);
if(findSolution) {
Rep(i ,N) {
fprintf(fp,"%d ", f[i+1]);
}
fprintf(fp,"\n");
} else {
fprintf(fp,"IMPOSSIBLE\n");
}
delete[] customer;
delete[] f;
}
fclose(fp);
}
-------------------------------------------------------------
On 8月27日, 下午9时28分, thomasan <[email protected]> wrote:
> Hello,everyone,
>
> This is the first time i participate in the GCJ contest, i am a
> little confused about the MilkShake problem in Round1A, is there any
> code solution to this problem writing in C++?
> Could somebody give your code solution to this problem to me, then i
> can read it as a reference! Thanks in advance!
>
> Best regards!
>
> /Thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---