ACPC10D
#include<iostream>
#include<cmath>
using namespace std;
int min(int a,int b)
{
if(a<b)
return a;
else
return b;
}
int main()
{
int t;cin>>t;int count=0;
while(t!=0)
{
count++;
int arr[t][3];
for(int j=0;j<t;j++)
for(int x=0;x<3;x++)
cin>>arr[j][x];
arr[0][2]+=arr[0][1];
arr[1][0]+=arr[0][1];
arr[1][1]+=min(arr[0][1],min(arr[1][0],arr[0][2]));
arr[1][2]+=min(arr[0][1],min(arr[1][1],arr[0][2]));
for(int j=2;j<t;j++)
{
arr[j][0] = arr[j][0] + min(arr[j-1][0],arr[j-1][1]);
arr[j][1] = arr[j][1] + min(arr[j][0],min(arr[j-1][0],min(arr[j-1][1],arr[j-1][2])));
arr[j][2] = arr[j][2] + min(arr[j][1],min(arr[j-1][1],arr[j-1][2]));
}
int lm = arr[t-1][1];
cout<<count<<". "<<lm<<endl;
cin>>t;
}
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
int min(int a,int b)
{
if(a<b)
return a;
else
return b;
}
int main()
{
int t;cin>>t;int count=0;
while(t!=0)
{
count++;
int arr[t][3];
for(int j=0;j<t;j++)
for(int x=0;x<3;x++)
cin>>arr[j][x];
arr[0][2]+=arr[0][1];
arr[1][0]+=arr[0][1];
arr[1][1]+=min(arr[0][1],min(arr[1][0],arr[0][2]));
arr[1][2]+=min(arr[0][1],min(arr[1][1],arr[0][2]));
for(int j=2;j<t;j++)
{
arr[j][0] = arr[j][0] + min(arr[j-1][0],arr[j-1][1]);
arr[j][1] = arr[j][1] + min(arr[j][0],min(arr[j-1][0],min(arr[j-1][1],arr[j-1][2])));
arr[j][2] = arr[j][2] + min(arr[j][1],min(arr[j-1][1],arr[j-1][2]));
}
int lm = arr[t-1][1];
cout<<count<<". "<<lm<<endl;
cin>>t;
}
return 0;
}
No comments:
Post a Comment