A. Traveling Salesman Problem
题目链接:
https://codeforces.com/contest/1713/problem/A
思路:
结果等于四个方向上绝对值之和的二倍
代码:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int a[4];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
memset(a,0,sizeof a);
int res=0;
while(n--)
{
int x,y;
cin>>x>>y;
if(x==0&&y>0)
{
a[0]=max(a[0],y);
}
else if(x==0 && y<0)
{
a[2]=max(a[2],abs(y));
}
else if(x>0 && y==0)
{
a[1]=max(a[1],x);
}
else if(x<0 && y==0)
{
a[3]=max(a[3],abs(x));
}
}
res=a[0]*2+a[1]*2+a[2]*2+a[3]*2;
cout<<res<<endl;
}
}
B. Optimal Reduction
题目链接:https://codeforces.com/contest/1713/problem/B
思路: 如果出现凹型,则输出NO。否则输出YES
代码:
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
vector<int>ve;
for(int i=0;i<n;i++)
{
int t;
cin>>t;
if(i!=0 && t==ve[ve.size()-1])
{
continue;
}
ve.push_back(t);
}
bool f=true;
for(int i=0;i<ve.size();i++)
{
int a=i-1;
int b=i+1;
if(a>=0 && b<ve.size())
{
if(ve[a]>ve[i] && ve[b]>ve[i])
{
f=false;
}
}
}
if(f)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
884

被折叠的 条评论
为什么被折叠?



