比赛做出的,哈哈,
#include<iostream>
#include<stdio.h>
using namespace std;
#define inf 100000000
int map[1001][1001];
void put(int n)
{
int i,j,k;
for (j=0;j<n;j++)
{
for (i=0;i<n;i++)
cout<<map[j][i]<<' ';
cout<<endl;
}
}
int main()
{
int i,j,k;
int p[10000];
int e[10000];
int n;
int t;
//cout<<"fdkj";
cin>>t;
int num=0;
while (t--)
{
num++;
scanf("%d",&n);
int total=0;
for (i=0;i<n;i++)
{
scanf("%d",e+i);
map[i][i]=0;
total+=e[i];
}
for (j=0;j<n;j++)
{
for (i=j+1;i<n;i++)
{
map[j][i]=map[j][i-1]+e[i-1];
map[i][j]=total-map[j][i];
}
}
//put(n);
printf("Case #%d:",num);
for (i=0;i<n;i++)
{
int ans=inf;
for (j=0;j<n;j++)
{
ans=min(ans,map[j][i]-e[(j-1+n)%n]);
ans=min(ans,map[i][j]-e[j]);
}
printf(" %d",ans+total);
}
printf("\n");
}
}
Journey
Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 5 Tried: 29
Description
In Tomb-sweeping Festival, Yangsir and her friends planned to have a journey in a park. The park has N attractions which form a circle and only between adjacent attractions there is a road, so there are N roads in total. On the way to the park, Yangsir and her friends lost their way. After several twists and turns, they arrived at the park but they still didn't know which attraction they are on now.
Looking at the park's map, Yangsir wanted to know that: if they set attraction X as starting point, what is the minimum time they needed to pass all N attractions at least once? They don't need to go back to the starting attraction and the time spend on attractions are ignored.
We number the N attractions from 1 to N clockwise, and the ith road is the road between ith and (i+1)th attraction, except that the Nth road is the road between N and 1. The N roads are all undirected.
Input
There are multiple test cases. The first line of the input will be an integer T (T <= 10) indicating the number of test cases.
For each test case, the first line is only one integer N (3 <= N <= 1000), representing the number of attractions in the park. In the second line there are N positive integers separated by one space representing the time needed to pass through the ith road. All the integers above are within 1,000,000.
Output
For each test case, print "Case #t: " first, in which t is the number of the test case starting from 1. Then output N integers separated by one space which are the minimum time needed if they start from 1st attraction, 2nd attraction,..., Nth attraction.
Simple Input
1
5
4 6 5 3 7
Simple Output
Case #1: 18 19 19 20 18
Source