HDU 2017 多校联合训练赛8 1008 6140 Hybrid Crystals
来源:互联网 发布:保温杯套子 淘宝 编辑:程序博客网 时间:2024/06/08 18:24
Hybrid Crystals
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Problem Description
> Kyber crystals, also called the living crystal or simply the kyber, and known as kaiburr crystals in ancient times, were rare, Force-attuned crystals that grew in nature and were found on scattered planets across the galaxy. They were used by the Jedi and the Sith in the construction of their lightsabers. As part of Jedi training, younglings were sent to the Crystal Caves of the ice planet of Ilum to mine crystals in order to construct their own lightsabers. The crystal's mix of unique lustre was called "the water of the kyber" by the Jedi. There were also larger, rarer crystals of great power and that, according to legends, were used at the heart of ancient superweapons by the Sith.
>
> — Wookieepedia
Powerful, the Kyber crystals are. Even more powerful, the Kyber crystals get combined together. Powered by the Kyber crystals, the main weapon of the Death Star is, having the firepower of thousands of Star Destroyers.
Combining Kyber crystals is not an easy task. The combination should have a specific level of energy to be stablized. Your task is to develop a Droid program to combine Kyber crystals.
Each crystal has its level of energy (i -th crystal has an energy level of ai ). Each crystal is attuned to a particular side of the force, either the Light or the Dark. Light crystals emit positive energies, while dark crystals emit negative energies. In particular,
* For a light-side crystal of energy levelai , it emits +ai units of energy.
* For a dark-side crystal of energy levelai , it emits −ai units of energy.
Surprisingly, there are rare neutral crystals that can be tuned to either dark or light side. Once used, it emits either+ai or −ai units of energy, depending on which side it has been tuned to.
Givenn crystals' energy levels ai and types bi (1≤i≤n ),bi=N means the i -th crystal is a neutral one, bi=L means a Light one, and bi=D means a Dark one. The Jedi Council asked you to choose some crystals to form a larger hybrid crystal. To make sure it is stable, the final energy level (the sum of the energy emission of all chosen crystals) of the hybrid crystal must be exactlyk .
Considering the NP-Hardness of this problem, the Jedi Council puts some additional constraints to the array such that the problem is greatly simplified.
First, the Council puts a special crystal ofa1=1,b1=N .
Second, the Council has arranged the othern−1 crystals in a way that
ai≤∑j=1i−1aj[bj=N]+∑j=1i−1aj[bi=L∩bj=L]+∑j=1i−1aj[bi=D∩bj=D](2≤i≤n).
[cond] evaluates to 1 if cond holds, otherwise it evaluates to 0 .
For those who do not have the patience to read the problem statements, the problem asks you to find whether there exists a setS⊆{1,2,…,n} and values si for all i∈S such that
∑i∈Sai∗si=k,
wheresi=1 if the i -th crystal is a Light one, si=−1 if the i -th crystal is a Dark one, and si∈{−1,1} if the i -th crystal is a neutral one.
>
> — Wookieepedia
Powerful, the Kyber crystals are. Even more powerful, the Kyber crystals get combined together. Powered by the Kyber crystals, the main weapon of the Death Star is, having the firepower of thousands of Star Destroyers.
Combining Kyber crystals is not an easy task. The combination should have a specific level of energy to be stablized. Your task is to develop a Droid program to combine Kyber crystals.
Each crystal has its level of energy (
* For a light-side crystal of energy level
* For a dark-side crystal of energy level
Surprisingly, there are rare neutral crystals that can be tuned to either dark or light side. Once used, it emits either
Given
Considering the NP-Hardness of this problem, the Jedi Council puts some additional constraints to the array such that the problem is greatly simplified.
First, the Council puts a special crystal of
Second, the Council has arranged the other
For those who do not have the patience to read the problem statements, the problem asks you to find whether there exists a set
where
Input
The first line of the input contains an integer T , denoting the number of test cases.
For each test case, the first line contains two integersn (1≤n≤103 ) and k (|k|≤106 ).
The next line containsn integer a1,a2,...,an (0≤ai≤103 ).
The next line containsn character b1,b2,...,bn (bi∈{L,D,N} ).
For each test case, the first line contains two integers
The next line contains
The next line contains
Output
If there exists such a subset, output "yes", otherwise output "no".
Sample Input
25 9 1 1 2 3 4N N N N N 6 -101 0 1 2 3 1N L L L L D
Sample Output
yesno
Source
2017 Multi-University Training Contest - Team 8
题目大意
给出n个数,每个数对应一个属性,L代表正数,D代表负数,N代表可能为正数可能为负数,现在,要求判断能不能用给出的数相加组成k。
【敲黑板】题目为了减低难度,还给出了两个条件,这也正是解题的关键。
1.每组数据中的第一个数a1,数值一定是1,并且属性一定为N。
2.除第一个数之外的n-1个数都满足条件ai≤∑j=1i−1aj[bj=N]+∑j=1i−1aj[bi=L∩bj=L]+∑j=1i−1aj[bi=D∩bj=D](2≤i≤n).
假设ai属性为L,ai <= 下标在1~i-1的所有属性为N的数之和 + 下标在1~i-1的所有属性为L的数之和;
假设ai属性为D,ai <= 下标在1~i-1的所有属性为N的数之和 + 下标在1~i-1的所有属性为D的数之和;
假设ai属性为N,ai <= 下标在1~i-1的所有属性为N的数之和 。
题目分析
因为数据范围n<=1000,所以记录所有能凑出来的小于10^6的数,一定会TLE的。所以理解题目给出的附加条件就显得尤为重要了。
(属性为N的数既可以作为L也可以作为D看待),如果我们只关注序列中属性为L和N的数,那么第一个数为1,第二个数<=1,即0或1;第三个数<=前两个数之和,依次类推。现在假设序列中属性为L和N的前4个数为1、1、2、3。那么前两个数的和是2,他们可以组成小于等于2的所有自然数;前三个数的和为4,并且可以组成小于等于4的所有自然数;再加上第四个数3,那么前四个数可以组成所有[1, 4]和[5, 7]的所有数。所以,我们只要确定所有数能组成的最大数,就能确定我们能组成0~最大数区间内的所有数。属性为D和N的数同理可得我们能组成的最小数。最后只需要判断k是否在 最大数~最小数 的区间内,即可判断能否组成k。。
程序其实有一个漏洞,当k==0的时候,程序作出的判断有可能是错的,但是按照题意,组成一个能量为0的水晶好像并没有什么用,并且数据也没有涉及。
代码
参考
http://blog.csdn.net/young_12138/article/details/77341341
题目大意
给出n个数,每个数对应一个属性,L代表正数,D代表负数,N代表可能为正数可能为负数,现在,要求判断能不能用给出的数相加组成k。
【敲黑板】题目为了减低难度,还给出了两个条件,这也正是解题的关键。
1.每组数据中的第一个数a1,数值一定是1,并且属性一定为N。
2.除第一个数之外的n-1个数都满足条件
假设ai属性为L,ai <= 下标在1~i-1的所有属性为N的数之和 + 下标在1~i-1的所有属性为L的数之和;
假设ai属性为D,ai <= 下标在1~i-1的所有属性为N的数之和 + 下标在1~i-1的所有属性为D的数之和;
假设ai属性为N,ai <= 下标在1~i-1的所有属性为N的数之和 。
题目分析
因为数据范围n<=1000,所以记录所有能凑出来的小于10^6的数,一定会TLE的。所以理解题目给出的附加条件就显得尤为重要了。
(属性为N的数既可以作为L也可以作为D看待),如果我们只关注序列中属性为L和N的数,那么第一个数为1,第二个数<=1,即0或1;第三个数<=前两个数之和,依次类推。现在假设序列中属性为L和N的前4个数为1、1、2、3。那么前两个数的和是2,他们可以组成小于等于2的所有自然数;前三个数的和为4,并且可以组成小于等于4的所有自然数;再加上第四个数3,那么前四个数可以组成所有[1, 4]和[5, 7]的所有数。所以,我们只要确定所有数能组成的最大数,就能确定我们能组成0~最大数区间内的所有数。属性为D和N的数同理可得我们能组成的最小数。最后只需要判断k是否在 最大数~最小数 的区间内,即可判断能否组成k。。
程序其实有一个漏洞,当k==0的时候,程序作出的判断有可能是错的,但是按照题意,组成一个能量为0的水晶好像并没有什么用,并且数据也没有涉及。
代码
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int T, n, k;int v[1005];char c[1005];int l, r;int main(){ scanf ("%d",&T); while (T--) { scanf ("%d %d",&n,&k); for (int i=0; i<n; ++i) { scanf ("%d",&v[i]); } getchar(); for (int i=0; i<n; ++i) { scanf ("%c",&c[i]); getchar(); } l = r = 0; for (int i=0; i<n; ++i) { if (c[i] == 'L') r += v[i]; else if(c[i] == 'D') l -= v[i]; else if(c[i] == 'N') { r += v[i]; l -= v[i]; } } if (k<=r && k>=l) printf("yes\n"); else printf("no\n"); } return 0;}
参考
http://blog.csdn.net/young_12138/article/details/77341341
阅读全文
0 0
- HDU 2017 多校联合训练赛8 1008 6140 Hybrid Crystals
- 2017 HDU 6140 多校联合赛 Hybrid Crystals
- 2017多校联合第8场1008/hdu 6140Hybrid Crystals(思维)
- HDU-2017 多校训练赛8-1008-Hybrid Crystals
- HDU 6140 Hybrid Crystals
- hdu 6140 Hybrid Crystals
- hdu-6140Hybrid Crystals
- HDU 6140 Hybrid Crystals
- HDU 6140 Hybrid Crystals
- HDU 6140 Hybrid Crystals
- 2017多校八 1008题 hdu 6140 Hybrid Crystals 推理
- 2017多校八 1008题 hdu 6140 Hybrid Crystals 推理
- 【多校训练】hdu 6140 Hybrid Crystals
- hdu 6140 Hybrid Crystals 思维
- Hdu 6140 Hybrid Crystals【思维】
- Hybrid Crystals(HDU 6140)
- HDU 6140 Hybrid Crystals【思维】
- 2017多校8-1008 Hybrid Crystals
- JSP页面乱码
- 多线程访问同一资源第三步 : 生产者和消费者模式 用synchronized
- 删除.gradle文件夹下的全部内容,打开Android Studio卡在Refreshing gradle project
- Oracle学习笔记day05——DML语言
- 第三方登录(微博)
- HDU 2017 多校联合训练赛8 1008 6140 Hybrid Crystals
- Opencv Mat的三种常用类型简介
- 百度之星资格赛1001度度熊保护村庄
- Excel提取员工名单,就这么快
- 僵尸进程如何产生的
- UVA 1329 Corporative Network
- HDU 3336 Count the string(深入理解KMP算法)【模板】
- 初三上学期待学习内容(实时更新)
- Android检查手机是否被root