#include<iostream>
using namespace std;
int n,m;
int g[N][N];
int dis[N],path[N*2];
int cnt;
void dfs(int i)
{
for(int j=1;j<=n;j++)
if(g[i][j])
{
g[i][j]=0;
g[j][i]=0;
dfs(j);
}
path[cnt++]=i;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
g[x][y]=1;
g[y][x]=1;
dis[x]++;
dis[y]++;
}
int start=1;
int sum=0;
for(int i=1;i<=n;i++)
if(dis[i]%2)
{
sum++;
if(sum==1)
start=i;
}
dfs(start);
for(int i=cnt-1;i>=0;i--)
cout<<path[i]<<" ";
return 0;
}
二、一本通 1374 铲雪车
2.1 问题描述
2.2 问题解决
#include<iostream>
using namespace std;
int main()
{
long long start,endd;
long long x1,y1,x2,y2;
double dis=0;
cin>>start>>endd;
while(scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2)!=EOF)
dis+=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
double ans=dis*2/1000/20;
long long h=(long long)(ans);
long long m=(long long)((ans-h)*60+0.5);
printf("%lld:%02lld\n",h,m);
return 0;
}
三、蓝桥杯 11届
3.1 问题描述
3.2 问题解决
#include <iostream>
#include <set>
using namespace std;
typedef pair<double, double> PDD;
set<PDD> line;
int res = 1;
void compute(double x, double y)
{
set<PDD> points;
PDD iter;
for(set<PDD>::iterator l = line.begin(); l != line.end(); l ++)
{
double a = l->first, b = l->second;
if(a != x)
{
iter.first = (b - y) / (x - a);
iter.second = iter.first * x + y;
points.insert(iter);
}
}
res += points.size();
}
int main()
{
int n;
cin >> n;
while(n --)
{
double x, y;
cin >> x >> y;
int m = line.size();
line.insert(make_pair(x, y));
if(m != line.size())
{
res ++;
compute(x, y);
}
}
cout << res << endl;
return 0;
}