Lotus and Characters (stronger)】的更多相关文章

题意: 有n类物品,第i种物品权值为$val(i)$,有$cnt(i)$个,现在你可以选出一些物品排成一个序列(假设有m个), 记第i个物品种类为$x_i$,最大化$\sum_{i=1}^m{i * val(x_i)}$ 解法: 只要将物品分为两类即可. 对于$val(i) \ge 0$的直接从小到大排列插入序列末端即可,然后在序列首端插入物品, 记当前后缀和为$suffixsum$. 接下来从大到小插入$val(i)<0$的物品,每插入一个会产生$suffixsum+val(i)$的答案贡献,…
 Lotus and Characters  问题描述 Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串. 定义串的价值为:第1位字母的价值*1+第2位字母的价值*2+第3位字母的价值*3…… 求Lotus能构造出的串的最大价值.(可以构造空串,因此答案肯定\geq 0≥0) 输入描述 第一行是数据组数T(0 \leq T \leq 1000)T(0≤T≤1000). 对于每组数据,第一行一个整数n(1 \leq n \leq 26)n(1≤n≤26),…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意: Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串. 定义串的价值为:第1位字母的价值*1+第2位字母的价值*2+第3位字母的价值*3…… 求Lotus能构造出的串的最大价值.(可以构造空串,因此答案肯定\geq 0≥0) 分析: 做这个题目的时候,第一感觉回溯算了,不用想,肯定T了. #include <bits/stdc++.h> usin…
http://acm.hdu.edu.cn/showproblem.php?pid=6011 先把数字从小到大排好,比如是-6.3.4这样, 然后处理出后缀和,当后缀和 <= 0的时候马上停止就好了. 证明: 假如现在是去到了第二个,也就是那个3,后缀和是7,那么我选不选-6呢? 如果选, 结果是: 1 * (-6) + 2 * 3 + 3 * 4 = 1 * (-6) + 3 + 4 + [1 * 3 + 2 * 4] 此时后缀和 > 0,对答案是有贡献的. #include <cst…
http://acm.hdu.edu.cn/showproblem.php?pid=6011 题意:共有n种字符,每种字符有一个val和一个cnt,代表这个字符的价值和数量.可以制造的总价值是:第一个字符的权值*1+第二个字符的权值*2+第三个字符的权值*3+…….问最大的总价值可以是多少. 思路:首先可以确定价值越大的是放在越后,因为后面的位权比较大.考虑到价值有负数,因为不确定负数是否要放上去,所以需要枚举这些负数. 首先输入的时候记录价值为负的个数negnum.将价值从小到大排序,然后枚举…
每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余方程 NOIP2007统计数字 NOIP2013火柴排队 NOIP2013花匠 2016.06.05 Uva 组装电脑 12124 - Assemble Uva 派 (Pie,NWERC 2006,LA 3635) 2016.06.19 Uva 网络(Network,Seoul 2007,LA 39…
题目描述 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest…
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"…
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Th…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = “eceba” and k = 2, T is "ece" which its length is 3. 这道题是之前那道Longest Substring with At Most Two Distinct Characters的拓展…
Given a string S, find the length of the longest substring T that contains at most two distinct characters.For example,Given S = “eceba”,T is “ece” which its length is 3. 这道题给我们一个字符串,让我们求最多有两个不同字符的最长子串.那么我们首先想到的是用哈希表来做,哈希表记录每个字符的出现次数,然后如果哈希表中的映射数量超过两…
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file. By using the read4 API, implement the function…
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the file.By using the read4 API, implement the function i…
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst…
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.…
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.…
Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details. This warning can be disabled by using the comman…
题目描述: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest…
BeautifulSoup很赞的东西 最近出现一个问题:Python 3.3 soup=BeautifulSoup(urllib.request.urlopen(url_path),"html.parser") soup.findAll("a",{"href":re.compile('^http|^/')}) 出现warning: Some characters could not be decoded, and were replaced wi…
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.…
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http://blog.csdn.net/fightforyourdream/article/details/17860983 这算法写了很多次, 时间太长, 半年前, 有一次写了二个小时, 写不下去, 想法不好, 没有办法收场; 接着, 又写了四天, 每天二小时, 把上次代码拿出来看, 有什么问题, 改写.…
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure? 这道题让我们判断一个字符串中是否有重复的字符,要求不用特殊的数据结构,这里应该是指哈希表之类的不让用.像普通的整型数组应该还是能用的,这道题的小技巧就是用整型数组来代替哈希表,在之前Bitwise AND of Numbers Range 数…
题目: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'…
CI中URI传递参数时,出现:The URI you submitted has disallowed characters.错误 .原因:这是由于uri中存在CI不允许的字符 . 解决办法:在config/config.php文件中,找到 复制代码 代码如下: $config[permitted_uri_chars] = a-z 0-9'%.:_/-i; 在里面添加允许的字符 .如我需要添加@符号,则可以这样: 代码如下: $config[permitted_uri_chars] = a-z…
这篇介绍Characters资源包.包含三个文件夹:FirstPersonCharacter.RollerBall.ThirdPersonCharacter. FirstPersonCharacter文件夹: FPSController预设: 提供由CharacterController作限制的第一人称控制器预设,可模拟运动中头部晃动和脚步声. RigidBodyFPSController预设: 提供由碰撞体和刚体作限制的第一人称控制器预设,可模拟运动中头部晃动. MouseLook类: 非Mo…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T is "ece" which its length is 3. 我的做法:维护一个window,r移动到超出k distinct character限制是更新max,然后移动…
LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLongestSubstring(string s) { int ans = 0, i = 0, j = 0; map <char , char> m; int n = s.size(); while (i < n && j < n){ // 左闭右开 if(m.find(s…
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst…
题目: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of…
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Th…