牛客网-颜料的混合【思维】

链接:https://www.nowcoder.com/acm/contest/118/C
来源:牛客网

艺术家通常要通过颜料的混合得到某种他想要的但又不是从工厂里面生产出来的原始的那种颜料。为了简便起见, 我们假设每种颜料都可以分成是红绿两个分量的数值指标, 即每种颜料都可以用红绿在其中占据的百分比来表示。艺术家从工厂拿回了三种不同颜料分别是(x1%红,y1%绿), (x2%红,y2%绿),(x3%红,y3%绿), 问艺术家是否能够调出自己想要的颜料(x0%红,y0%绿)?    
输入描述:
八个整数:x0,y0,x1,y1,x2,y2,x3,y3。(0 < xi, yi < 100)
输出描述:
输出Yes如果可以调出, 否则输出No

示例1

输入

2 3
1 1
3 3
2 4

输出

Yes

说明

一份颜料一, 一份颜料二, 一份颜料三混合即可。


备注:
输入数据有多组!输入数据有多组!输入数据有多组!

解题思路:这题的难点在于通过题面想到向量构造坐标的问题。三个向量能构成的坐标在这三个点所构成的三角形内。

所以问题就转化为求该点是否在三角形内(用面积法)。

三角形面积:

|x1 y1 1|

|x2 y2 1|

|x3 y3 1|

向量叉乘得:s = x1 * y2 + x2 * y3 + y1 * x3 - x3 * y2 - x2 * y1 - y3 * x1

附ac代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <string>
 5 #include <cmath>
 6 #include <string>
 7 #include <iostream>
 8 #include <map>
 9 #include <queue>
10 #include <stack>
11 #include <cstdlib>
12 const int maxn = 2 * 1e5 + 10;
13 const int inf = 0x3f3f3f3f;
14 
15 using namespace std;
16 typedef long long ll;
17 const ll mod = 1e9 + 7;
18 ll getarea(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3)
19 {
20     ll ans = x1 * y2 + y1 * x3 + x2 * y3 - x3 * y2 - x2 * y1 - y3 * x1;
21     return ans;
22 }
23 int main(int argc, const char * argv[]) {
24     ll x0, y0, x1, y1, x2, y2, x3, y3;
25 
26     while(~scanf("%lld%lld%lld%lld%lld%lld%lld%lld",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3))
27     {
28         ll ans1 = getarea(x0, y0, x1, y1, x2, y2);
29         ll ans2 = getarea(x0, y0, x2, y2, x3, y3);
30         ll ans3 = getarea(x0, y0, x1, y1, x3, y3);
31         ll ans4 = getarea(x1, y1, x2, y2, x3, y3);
32       //  printf("%lld %lld %lld %lld", ans4, ans1, ans2, ans3);
33         if(abs(ans4) == abs(ans1) + abs(ans2) + abs(ans3))
34         puts("Yes");
35         else puts("No");
36     }
37 
38     return 0;
39 }
View Code

猜你喜欢

转载自www.cnblogs.com/zmin/p/9039117.html