公司网站不备案,青岛企业如何建网站,天津市建设公司网站,绿标短网址生成L Grayscale Confusion
思路#xff1a;题解 | #Grayscale Confusion# 大概相当于是一个构造题#xff0c;将(r, g, b)映射为函数值#xff0c;满足大小关系以及最初两组(c0和c1)rgb的值相等
f(r, g, b) x*r y*g z*b
x y z 1c0和c1有大小#xff0c;无法满足…L Grayscale Confusion
思路题解 | #Grayscale Confusion# 大概相当于是一个构造题将(r, g, b)映射为函数值满足大小关系以及最初两组(c0和c1)rgb的值相等
f(r, g, b) x*r y*g z*b
x y z 1c0和c1有大小无法满足输出-1c0和c1有一个相等假设r0r1相等就令x 1, y 0, z 0c0和c1有交错假设是r0 r1, g0 g1令p r0 - r1
q g1 - g0
x q / (p q)
y p / (p q)则f(c0) - f(c1) q / (p q) * q - p / (p q) * p 0看懂了之后自己打了一遍 尤其注意的是公式得到的值是double最后不能直接取整要用lround因此得过一次93.3333的高分
lround(double)将浮点值舍入为最接近的整数
#include iostream
#include cstdio
#include algorithm
#include queue
#include vector
#include cstring
#include map
#include cmath
#include ctime
#include cstdlib
using namespace std;#define N 1005int c[N][3];
double f[3];bool bigger(int x, int y)
{if (c[x][0] c[y][0] c[x][1] c[y][1] c[x][2] c[y][2]) return true;return false;
}int main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int n;cin n;for (int i 0; i n; i){cin c[i][0] c[i][1] c[i][2];}if (bigger(0, 1) || bigger(1, 0)){cout -1 endl;return 0;}f[0] f[1] f[2] 0;int fl 0;for (int i 0; i 3; i){if (c[0][i] c[1][i]){f[i] 1;fl 1;break;}}if (!fl){int x 0, y 0;for (int i 0; i 3; i){if (c[0][i] c[1][i]) x i;else y i;}double p c[0][x] - c[1][x], q c[1][y] - c[0][y];f[x] q / (p q);f[y] p / (p q);}for (int i 0; i n; i){double res 0;for (int j 0; j 3; j){res f[j] * c[i][j];}cout lround(res) endl;}return 0;
}