## SDUT 2021 Spring Individual Contest(for 20) - 10 补题

Question B Minimal Area
Question meaning: give you every point of a strictly polygonal area, let you find the minimum area of ​​a triangle composed of any three points.
Idea: From the question meaning, know that the triangle composed of three adjacent points has the smallest area. Therefore, we traverse all possible points to find the smallest value. The formula for finding the area of ​​a triangle with three points is S = 1/2 * |(x2-x1) * (y3-y1)-(y2-y1) * (x3-x1 )|

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
#define inf 0x3f3f3f3f3f3f3f3f
struct node {

ll x,y;
}s[N];
int main()
{

ll n;
cin>>n;
for(int i=0;i<n;i++)
{

cin>>s[i].x>>s[i].y;
}
ll ans=inf;
for(int i=0;i<n;i++)
{

ll x1=s[(i-1+n)%n].x-s[(i-2+n)%n].x;
ll y1=s[(i-1+n)%n].y-s[(i-2+n)%n].y;
ll x2=s[i].x-s[(i-1+n)%n].x;
ll y2=s[i].y-s[(i-1+n)%n].y;
ll now=abs(x1*y2-x2*y1);
ans=min(ans,now);
}
cout<<ans<<endl;
return 0;
}
``````

K question Video Reviews
question meaning: there are n people (with order), for i, if there is ai person in front of it, then i will join. You can force any person to join, and ask what is the minimum number of forced times for the number of people to join to reach m
Idea: Dichotomy + Greedy. Force the people in front first, because the people in front will make contributions to the people behind, so that the optimal solution can be guaranteed, and then the two points are used to judge whether the conditions are met, and the final answer and m are taken to the minimum

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int a[N];
int n,m;
bool check(int k)
{

int ans=0;
for(int i=0;i<n;i++)
{

if(a[i]<=ans)
ans++;
else if(k)
{

ans++;
k--;
}
if(ans==m)
return true;
}
return false;
}
int main()
{

cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
int l=0;
int r=m;
int ans;
while(l<=r)
{

int mid=l+r>>1;
if(check(mid))
{

r=mid-1;
ans=mid;
}
else
{

l=mid+1;
}
}
cout<<min(m,ans)<<endl;
return 0;
}
``````

### Guess you like

Origin blog.csdn.net/weixin_51768569/article/details/115308569
Recommended
Ranking
Daily