4
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MaxN=109;
const int INF=1000000000;
int N,M;
vector e[MaxN];
vector> Go[MaxN];
int A[MaxN],B[MaxN],F[MaxN],G[MaxN];
void init()
{
for(int i=1;i<=N;i++)
e[i].clear();
for(int i=1;i<=N;i++)
{
int x;
scanf("%d%d%d",&A[i],&B[i],&x);
B[i]+=x;
if(A[i]>=B[i]);
else
A[i]=B[i];
}
for(int i=1;i=0;i--)
{
if(F[x]-G[x]
#include
#include
#include
const int MAXN=1100007;
const int MAXR=20;
const int MAXC=10;
typedef unsigned char _char;
struct Tstack
{
static const int MAXS=MAXN;
int len;
int data[MAXS];
void clear(void){len=0;}
void push(int k){data[++len]=k;}
int pop(void){return data[len--];}
inline bool empty(){return len==0;}
};
const int exp4[]={0x000003,0x00000C,0x000003,0x000030,0x0000C0,0x000300,0x000C00,
0x003000,0x00C000,0x030000,0x0C0000,0x30000,0xC00000};
const int div4[]={0,2,4,6,8,10,12,14,16,18,20,22};
int r,c;
_char f[MAXR][MAXC][MAXN];
int l[MAXR][MAXC][MAXN];
Tstack s[2];
bool a[MAXR][MAXC];
int ans[MAXR][MAXC];
bool path[MAXR][MAXC];
int maxlen=0;
void init()
{
int i,j;
char str[20];
for(i=0;ib?a:b;
}
inline int getbit(int k,int n)
{
return ((k&exp4[n])>>div4[n]);
}
inline int changebit(int k,int n,int m)
{
return k-(k&exp4[n])+(m<0)
{
++t;
i=getbit(k,t);
if(i==1)
++s;
else if(i==2)
--s;
}
k=changebit(k,t,1);
return k;
}
inline int changeR(int k,int j)
{
k=changebit(changebit(k,j,3),j+1,3);
int t=j,s=1,i;
while(s>0)
{
--t;
i=getbit(k,t);
if(i==2)
++s;
else if(i==1)
--s;
}
k=changebit(k,t,2);
return k;
}
inline void updata(_char hash[],int path[],Tstack &s,int k,_char v,int last)
{
if(hash[k]==0xff)
{
hash[k]=v;
path[k]=last;
s.push(k);
}
else if(v>hash[k])
{
hash[k]=v;
path[k]=last;
}
}
inline bool ok(int k)
{
int i,j;
for(i=0;imaxlen)
maxlen=s[last].len;
while(!s[last].empty())
{
k=s[last].pop();
d=f[i][j][k];
left=getbit(k,j);
up=getbit(k,j+1);
if(a[i][j])
{
if((left==2)&&(up==1))
{
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,3),j+1,3),d+1,k);
}
else if((left==0)&&(up==0))
{
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,1),j+1,2),d+1,k);
}
else if((left==1)&&(up==1))
{
updata(f[i][j+1],l[i][j+1],s[now],changeL(k,j),d+1,k);
}
else if((left==2)&&(up==2))
{
updata(f[i][j+1],l[i][j+1],s[now],changeR(k,j),d+1,k);
}
else if((left==0)&&(up<3))
{
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,up),j+1,3),d+1,k);
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,3),j+1,up),d+1,k);
}
else if((left<3)&&(up==0))
{
if((j+2>c)||(getbit(k,j+2)!=3))
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,left),j+1,3),d+1,k);
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,3),j+1,left),d+1,k);
}
}
if(((left==0)||(left==3))&&((up==0)||(up==3)))
{
if((up==3)&&((j+2>c)||(getbit(k,j+2)==0)))
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,0),j+1,3),d,k);
else
updata(f[i][j+1],l[i][j+1],s[now],changebit(changebit(k,j,0),j+1,0),d,k);
}
}
}
if(i==(r-1))
break;
now^=1;
last^=1;
s[now].clear();
while(!s[last].empty())
{
k=s[last].pop();
d=f[i][c][k];
left=getbit(k,c);
if((left==0)||(left==3))
updata(f[i+1][0],l[i+1][0],s[now],changebit(k,c,0)<<2,d,k);
}
}
int anslen=-1;
k=-1;
while(!s[now].empty())
{
k=s[now].pop();
if(ok(k)&&(f[i][c][k]>anslen))
{
anslen=f[i][c][k];
t=k;
}
}
for(i=r-1;i>=0;--i)
for(j=c;j>=0;--j)
{
k=t;
ans[i][j]=k;
t=l[i][j][k];
}
d=0;
memset(path,0,sizeof(path));
for(i=0;id)
path[i][j]=true;
d=k;
}
for(i=0;i
#include
#include
#include
#include
const int MAXN=110;
const int COSA=0.5;
int s,p,d,h;
int a[MAXN][MAXN];
double ans;
void init()
{
scanf("%d %d %d",&p,&d,&h);
int i,j;
for(i=1;i<=s;++i)
{
for(j=1;j<=p+1-(i&1);++j)
scanf("%d",&a[i][j]);
}
}
void makeswap(int &a,int &b)
{
if(a>b)
{
int t=a;
a=b;
b=t;
}
}
inline double gettri(double a,double b)
{
return sqrt(a*a+b*b-2*a*b*COSA);
}
inline double gethalflong(int a,int b,int c,int l,int r)
{
if(l>r)
return 0;
double L=gettri(double(l-a)/double(b-a)*d,double(l-a)/double(c-a)*d);
double R=gettri(double(r-a)/double(b-a)*d,double(r-a)/double(c-a)*d);
return (L+R)*((r-l)/h+1)/2;
}
double getlong(int a,int b,int c)
{
makeswap(a,b);
makeswap(b,c);
makeswap(a,b);
double ret;
int l,m1,m2,r;
if(a==c)
{
if(a%h==0)
return d*1.5;
}
if(a==b)
{
l=(a/h)*h;
if(l
#include
#include
#include
const long MAXN=110;
const long INF=1e+6;
struct Tpoint
{
long x,y;
};
long n,p1,p2;
Tpoint a[MAXN];
float f[MAXN][MAXN];
long lx[MAXN][MAXN],ly[MAXN][MAXN];
long ans1[MAXN],ans2[MAXN];
inline long sqr(long a)
{
return a*a;
}
inline float dis(Tpoint a,Tpoint b)
{
return sqrt(double(sqr(a.x-b.x)+sqr(a.y-b.y)));
}
inline float min(float a,float b)
{
return a=1;--i)
if((i==l1)||(ans1[i]!=ans1[i+1]))
printf("%ld",ans1[i]);
for(i=1;i<=l2;++i)
if((i==1)||(ans2[i]!=ans2[i-1]))
printf("%ld",ans2[i]);
printf("\n");
}
int main()
{
long CASE=0;
while((scanf("%ld %ld %ld",&n,&p1,&p2)!=EOF)&&n)
{
printf("Case %ld: ",++CASE);
init();
solve();
}
return 0;
}