2013 ACM/ICPC Asia Regional Changsha Online - C Color Representation Conversion
这个纯粹是一个细节题啊!!!
由于某个地方的浮点数比较写错了,WA了无数次啊……
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
char str1[],str2[];
double h,s,l,r,g,b,v;
bool is(double h,double a,double b)
{
if(h-a>=-1e-&&h-b<1e-) return ; //这里忘记加-,一直是WA……
return ;
}
void v_r()
{
double c=v*s;
double hh=h/60.0;
double x=c*(-fabs(fmod(hh,2.0)-1.0));
r=g=b=;
if(is(hh,,))r=c,g=x;
else if(is(hh,,)) r=x,g=c;
else if(is(hh,,)) g=c,b=x;
else if(is(hh,,)) g=x,b=c;
else if(is(hh,,)) r=x,b=c;
else if(is(hh,,)) r=c,b=x;
double m=v-c;
r+=m;
g+=m;
b+=m;
}
void l_r()
{
double c=(1.0-fabs(2.0*l-1.0))*s;
double hh=h/60.0;
double x=c*(1.0-fabs(fmod(hh,2.0)-1.0));
r=g=b=;
if(is(hh,,))r=c,g=x;
else if(is(hh,,)) r=x,g=c;
else if(is(hh,,)) g=c,b=x;
else if(is(hh,,)) g=x,b=c;
else if(is(hh,,)) r=x,b=c;
else if(is(hh,,)) r=c,b=x;
double m=l-c*0.5;
r+=m;
g+=m;
b+=m;
}
void r_l_v(char c)
{
double ma=max(max(r,g),b);
double mi=min(min(r,g),b),t=ma-mi;
if(ma-mi<1e-) h=;
else if(ma-r<1e-&&g>=b) h=*(g-b)/t;
else if(ma-r<1e-&&g<b) h=*(g-b)/t+;
else if(ma-g<1e-) h=*(b-r)/t+;
else if(ma-b<1e-) h=*(r-g)/t+;
l=(ma+mi)*0.5;
v=ma;
if(c=='L'){
if(fabs(l)<=1e-||fabs(t)<=1e-) s=;
else if(l-0.5<=1e-) s=t/2.0/l;
else s=t/(-*l);
}
else{
if(fabs(ma)<1e-) s=;
else s=-mi/ma;
}
}
int main()
{
while(scanf("%s",str1)!=EOF){
scanf("%s",str2);
if(str2[]=='L'){
scanf("%lf %lf%% %lf%%",&h,&s,&l);
if(str1[]=='L'){
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,s,l);
continue;
}
s/=;l/=;
l_r();
if(str1[]=='B')
printf("%s %.0lf %.0lf %.0lf\n",str1,round(*r),round(*g),round(*b));
else{
r_l_v('V');
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,round(*s),round(*v));
}
}
else if(str2[]=='V'){
scanf("%lf %lf%% %lf%%",&h,&s,&v);
if(str1[]=='V'){
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,s,v);
continue;
}
s/=;v/=;
v_r();
if(str1[]=='B')
printf("%s %.0lf %.0lf %.0lf\n",str1,round(*r),round(*g),round(*b));
else{
r_l_v('L');
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,round(*s),round(*l));
}
}
else if(str2[]=='B'){
scanf("%lf%lf%lf",&r,&g,&b);
if(str1[]=='B'){
printf("%s %.0lf %.0lf %.0lf\n",str1,r,g,b);
continue;
}
r/=;g/=;b/=;
if(str1[]=='L'){
r_l_v('L');
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,round(*s),round(*l));
}
else{
r_l_v('V');
printf("%s %.0lf %.0lf%% %.0lf%%\n",str1,h,round(*s),round(*v));
}
}
}
return ;
}
2013 ACM/ICPC Asia Regional Changsha Online - C Color Representation Conversion的更多相关文章
- 2013 ACM/ICPC Asia Regional Changsha Online G Goldbach
比赛的时候,被题目误导了,题目最后说结果可能很大,要取模,那时就想直接求会TLE的!!! 赛后才知道,坑啊………… 代码如下: #include<iostream> #include< ...
- 2013 ACM/ICPC Asia Regional Changsha Online - G(DP)
第一眼就想到DP,然后想了N久就想不到可以不重算的DP 最后没办法了 先算出来 再去重.. 因为最多只有三个 对于三个来说有三种组合情况 x+y+z, x*y*z, x*y+z 那要么 x,y,z都 ...
- 2013 ACM/ICPC Asia Regional Changsha Online - E
第一个被板刷的题 取余 依次算在周几 #include <iostream> #include<cstdio> #include<cstring> #include ...
- 2013 ACM/ICPC Asia Regional Changsha Online J Candies
AC了,但是不知道为什么,但是恶心的不得了~最近写代码,思路都非常清晰,但是代码各种bug~T.T~说说思路吧:二分~330ms~ 小队友fribbi的思路是离线250msAC~ 预处理solve函数 ...
- 2013 ACM/ICPC Asia Regional Changsha Online–C (模拟)
题目描述 略... 题解 注意控制精度即可....变量全部定义成double,结果round就行....妈蛋....被这题目恶心死了.... 代码: #include <iostream> ...
- 2013 ACM/ICPC Asia Regional Changsha Online – C题 Color Representation Conversion (坑爹模拟题)
题意:给你三种颜色表示模式,RGB,HSV和HSL,实现任意模式之间两两转化. 1.最好别看题目中给的转化公式描述,我觉得叙述的一点也不清楚,看维基百科,把维基百科上的公式一句一句翻译过来就好 2.在 ...
- 2013 ACM/ICPC Asia Regional Changsha Online - J
原题戳这里. 题意: 有一未知列数a1,a2,a3.....an, 已知s[i]=a[i-1]+a[i]+a[i] (1<i<n) s[1]=a[1]+a[2]; s[n]=a[n-1] ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
随机推荐
- strcpy/strlen/strcat/strcmp面试总结
<strcpy拷贝越界问题> 一. 程序一 #include<stdio.h> #include<string.h> void main() { char s[]= ...
- hdu 3172 Virtual Friends
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3172 并查集的运用... #include<algorithm> #include< ...
- 利用js排序html表格
在web前端开发中会遇到排序等功能,当然也可以用服务器端来排序,今天我做一个笔记,怎么用js来实现这些复杂的功能呢. 在学习这个之前一定得用html dom jquery 的知识,要不没有办法看明白的 ...
- ios8/sdk8/xcode6/iphone6(+)适配
AppIcon https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Ic ...
- Pintos修改优先级捐赠、嵌套捐赠、锁的获得与释放、信号量及PV操作
Pintos修改优先级捐赠.嵌套捐赠.锁的获得与释放.信号量及PV操作 原有的优先级更改的情况下面没有考虑到捐赠的情况,仅仅只是改变更改了当前线程的优先级,更别说恢复原本优先级了,所以不能通过任何有关 ...
- 网页设计师必备的10个CSS技巧
CSS是网页设计师的基础,对CSS的了解能使他们能够设计出更加美观别致的网页.使用CSS技巧来巧妙地处理CSS是非常令设计师着迷的事情.在CSS的深海世界里有很多有意思的东西,你只需要找到最适合你的就 ...
- 微软职位内部推荐-Senior Software Development Engineer H/F
微软近期Open的职位: Microsoft Engineering Center Paris (Xbox Music et Video) : Ingénieur en développement l ...
- 【转】linux root用户ifconfig报command not found
解决办法: 方法一: 直接输入su - 回车.就可以ifconfig了 方法二: /etc/profile 把下面if语句注释掉: #path Manipulation if ["EUID& ...
- C++四则运算出题器---有答案版
一.实验题目 四则运算扩展----能接受答案并判断对错然后给出成绩. 二.实验思路 在每次输出算式后面输入答案,然后判断对错,对则统计. 稍微优化了一下界面. 三.代码 // 12345.cpp : ...
- mysql 慢查询开启
相关博客: linux下开启mysql慢查询,分析查询语句 开启方法: 方法一:使用命令开启慢查询开启 mysql> show variables like "%long%" ...