当前位置: 首页 > news >正文

求网站建设网站优化工作公司的网络规划与设计

求网站建设网站优化工作,公司的网络规划与设计,网站营销活动页面制作,泊头网站制作案例题目链接#xff0c;题目描述 https://www.lintcode.com/problem/1017 在本题中#xff0c;每个大写字母代表从“0”到“f”的一些十六进制数字。红绿蓝三元色#AABBCC可以简写为#ABC。 例如#xff0c;#15c是颜色#1155cc的简写。现在#xff0c;定义两种颜色#ABCDEF和#UV…题目链接题目描述 https://www.lintcode.com/problem/1017 在本题中每个大写字母代表从“0”到“f”的一些十六进制数字。红绿蓝三元色#AABBCC可以简写为#ABC。 例如#15c是颜色#1155cc的简写。现在定义两种颜色#ABCDEF和#UVWXYZ之间的相似度是abs((AB - UV)^2 (CD - WX)^2 (EF - YZ)^2)。给定颜色#ABCDEF返回与#ABCDEF最相似即相似度最小且可以简写表示的7字符颜色也就是说它可以用类似#XYZ的形式表示。color 是一个长度为7的字符串。 color 是一个合法的RGB颜色: 对于每一个 i 0, color[i] 是一个 0 到 f的十六进制数字。 任何一个有最高相似度的答案都是正确的。 所有的输入输出都是小写字母输出应为7个字符的字符串。 样例 样例 1输入color #09f166 输出#11ee66 解释二者相似程度为 -(0x09 - 0x11)^2 -(0xf1 - 0xee)^2 - (0x66 - 0x66)^2 -64 -9 -0 -73. 这是所有能够简写的颜色里最接近的颜色。样例 2输入color #010000 输出#000000 解释二者相似程度为 -(0x01 - 0x00)^2 -(0x00 - 0x00)^2 - (0x00 - 0x00)^2 -1 -0 -0 -1. 这是所有能够简写的颜色里最接近的颜色。思路以及疑惑的地方 题目描述中给的公式是每2位平方相加。给的例子确是相减。看了其他题解才知道是是相加。 其他题解全是用的工具类库比如 int q Integer.parseInt(comp, 16); return String.format(%02x, 17 * q); 其实这样不太好知其然不知其所以然。底层进制计算新手估计很难写出来。 我的答案没用到工具类库而是自己写的16进制转10进制10进制转16进制的方法对于别的语言完全适用 解题关键点 第一步理解题目意思关键是请看代码 int closest1 int1 / 17 (int1 % 17 8 ? 1 : 0); //最接近的 第二步 参考其他题解。我没有用工具类库自己从0开始写了16进制转10进制10进制转16进制的方法 我的答案其他用工具类库的答案自己去看题解 public class Solution {/*** param color: the given color* return: a 7 character color that is most similar to the given color*/public String similarRGB(String color) {/*方法独立性 枚举我们可以发现颜色中的每一维都是独立的因此我们只需要分别计算出 color #ABCDEF中与 ABCD 和 EF 相似度最大的颜色即可。最终的答案为这三个颜色的结合。对于 AB我们要在 00 到 ff 中找到一个相似度最大的。在方法一中我们得知00 到 ff 均为 17 的倍数因此我们需要找到一个 17 的倍数使得其与 AB 的差的绝对值最小。显然当 AB mod 17 8 时取刚好比 AB 大的那个数当 AB mod 17 8 时取刚好比 AB 小或与 AB 相等的那个数。*/MapInteger, Character mapi new HashMap();mapi.put(10, a);mapi.put(11, b);mapi.put(12, c);mapi.put(13, d);mapi.put(14, e);mapi.put(15, f);MapCharacter, Integer mapc new HashMap();for (int k : mapi.keySet()) {mapc.put(mapi.get(k), k);}String s1 color.substring(1, 3);String s2 color.substring(3, 5);String s3 color.substring(5, 7);int int1 to10hex(s1, mapi, mapc);int int2 to10hex(s2, mapi, mapc);int int3 to10hex(s3, mapi, mapc);//System.out.println(s1 s2 s3);//System.out.println(int1 int2 int3);int closest1 int1 / 17 (int1 % 17 8 ? 1 : 0); //最接近的int closest2 int2 / 17 (int2 % 17 8 ? 1 : 0); //最接近的int closest3 int3 / 17 (int3 % 17 8 ? 1 : 0); //最接近的//System.out.println(最接近的closest1 closest2 closest3);String ans #;ans h10to16(closest1, mapi, mapc);ans h10to16(closest2, mapi, mapc);ans h10to16(closest3, mapi, mapc);return ans;}//16进制转十进制public static int to10hex(String s, MapInteger, Character mapi, MapCharacter, Integer mapc) {int ans 0;char[] chars s.toCharArray();int n chars.length;int pow 0;for (int i n - 1; i 0; i--) {char c chars[i];if (mapc.containsKey(c)) { // 10-15int num Integer.parseInt(mapc.get(c) );ans num * (int) (Math.pow(16, pow));} else {int num Integer.parseInt(c );ans num * (int) (Math.pow(16, pow));}pow;}return ans;}//10进制转16进制public static String h10to16(int n, MapInteger, Character mapi, MapCharacter, Integer mapc) {n*17;ListInteger list new ArrayList(); //先列出n的二进制表示boolean start false;for (int i 31; i 0; i--) {int a (n (1 i)) 0 ? 0 : 1;if(a1 !start){start true;}if(start) list.add(a);}//System.out.println(n list);//正对二进制表示每4个一组计算16进制int len list.size();int cnt 0;int sum0;ListString ll new ArrayList();for (int i len-1; i 0 ; i--) {sum (int)(Math.pow(2,cnt))*list.get(i);if(cnt4){if(sum 10) ll.add(sum);else ll.add(mapi.get(sum));sum0;cnt 0;}}if(sum 0){if(sum 10) ll.add(sum);else ll.add(mapi.get(sum));}Collections.reverse(ll);String ans ;for (String s : ll) {anss;}//System.out.println(ans);return ans.length()0?00: ans;}}
http://www.hkea.cn/news/14482180/

相关文章:

  • 外军网站建设国内培训网站建设
  • 网站维护推广怎么做洗化行业做网站
  • 网站运营维护工作内容枸橼酸西地那非片是什么
  • 物流网站建设的背景广州网站建设公司怎么样
  • 政务网站开发合同中国工业设计网站
  • 自己如何做家政网站兰州口碑营销
  • 锦州宝地建设集团有限公司网站常用的seo工具推荐
  • c 在网站开发方面有优势吗建设会员网站需要多少钱
  • 网站开发定价学校网站群建设 ppt
  • wordpress 站群系统上海企业网上公示
  • 怎么建设商城网站做一个网站得做多少个页面
  • 中国建设银行快捷付授权网站网站开发工程师社交
  • 网站推广营销怎么做网站建设的公司好做吗
  • 启航做网站好吗医院网站源码下载
  • 天津的网站建设公司客户管理系统内容
  • 手机上怎么做自己卖菜的网站seo站内优化最主要的是什么
  • 视频网站上市公司有哪些一浪网站建设
  • 织梦网站模板如何安装深圳网站开发公司哪家好
  • 网站规划建设案例如何配置iis网站
  • 有声阅读网站如何建设网店代运营是什么意思
  • 网站都有什么语言陕西旭泽建设有限公司网站
  • 专题网站建设方案wordpress单页面博客
  • 网站开发如何进行管理开发一个平台
  • 一个域名多个网站外贸 wordpress模板
  • 上海做展会的网站都有哪些浙江省城乡住房建设网站
  • 我想建立一个网站不知道怎么做啊东莞网络优化推广
  • 在地税网站怎么做税种认定哪个网站教做ppt模板
  • 黄山网站开发wordpress 标签前缀
  • dedecms精仿学校网站模板固戍网站建设
  • 网站备案一般需要多久做视频网站 视频放在哪