1.
#include <iostream>
using namespace std;
int a[501][501];
int main()
{
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = n; i>= 2; i --)
for (int j = 1; j <= n; j ++)
for (int k = j + 1; k <= n; k ++)
{
a[k][j] = a[j][k] = min(a[j][k], a[j][i] + a[i][k]);
if (j >= i && k >= i) sum += 2 * a[j][k];
}
cout << sum << endl;
return 0;
}
2.
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10;
int n = 6, m = 6;
int sx ,sy, tx, ty;
int A[N][N], vis[N][N];
int ans = 1e9;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
void dfs(int x, int y, int state, int cost)
{
// cout << x << "|" << y << "|" << cost << endl;
if (x == tx && y == ty)
{
ans = min(ans, cost);
return;
}
// if (vis[x][y]) return;
if (cost > ans) return;
for (int i = 0; i < 4; i ++ )
{
int _dx = dx[i];
int _dy = dy[i];
int nx = x + _dx, ny = y + _dy;
if (nx >= 1&&nx <=n&&ny>=1&&ny<=m&&vis[nx][ny] == 0)
{
int ncost = state * A[nx][ny];
int nstate = ncost % 4 + 1;
vis[nx][ny] =1;
dfs(nx,ny,nstate, ncost+cost);
vis[nx][ny] =0;
}
}
}
int main()
{
for (int i = 1; i <= 6; i ++ )
{
for (int j = 1; j <= 6 ; j ++ )
{
cin >> A[i][j];
}
}
cin >> sx>>sy>>tx>>ty;
sx++,sy++,tx++,ty++;
vis[sx][sy] = 1;
dfs(sx,sy,1,0);
cout << ans;
}
3.
#include<bits/stdc++.h>
using namespace std;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int day(int n)
{
int y=n/10000;
int m=n%10000/100;
int d=n%10000%100;
a[2]=(y%4==0&&y%100!=0||y%400==0?29:28);
while(m--)d+=a[m];
while(y--)d+=(y%4==0&&y%100!=0||y%400==0?366:365);
return d;
}
int main()
{
int a,b;
while(cin>>a>>b)cout<<abs(day(a)-day(b))+1<<endl;
}