苟蒻太懒了。。现在才写
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.
The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise.
4 6 15
No
3 2 7
Yes
6 11 6
Yes
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
题意:
但丁用黑檀木和白象牙攻击,黑檀木每次射击造成a点伤害,而白象牙b点,但丁必须造成精确的x点伤害才能击败怪兽,问能否造成?
心爱的鬼泣。。帅气的但丁
一维背包判断存在性,不多提
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1E4 + 10;
int f[maxn],a,b,c;
int main()
{
#ifdef YZY
freopen("yzy.txt","r",stdin);
#endif
cin >> a >> b >> c;
f[0] = 1;
for (int i = a; i <= c; i++)
if (f[i-a])
f[i] = 1;
for (int i = b; i <= c; i++)
if (f[i-b])
f[i] = 1;
if (f[c]) printf("Yes");
else printf("No");
return 0;
}
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?
The only line of input contains an integer m (1 ≤ m ≤ 100 000) — the required number of trailing zeroes in factorial.
First print k — the number of values of n such that the factorial of n ends with m zeroes. Then print these k integers in increasing order.
1
5 5 6 7 8 9
5
0
The factorial of n is equal to the product of all integers from 1 to n inclusive, that is n! = 1·2·3·...·n.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
题意:
给出整数n,问有多少个数的阶乘,刚好有n个后缀0
题解:
2*5 = 10有一个0不多说,当数字逐渐增大,其分解质因数后含有的2数量必远远大于5,所以统计5的个数即可
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1E5 + 10;
int ans[maxn],tot,m;
int main()
{
#ifdef YZY
freopen("yzy.txt","r",stdin);
#endif
cin >> m;
int sum = 0;
for(int i = 5; ; i++) {
int k = i;
while (k % 5 == 0) k/=5,++tot;
if (tot == m) ans[++sum] = i;
if (tot > m) break;
}
printf("%d\n",sum);
for (int i = 1; i <= sum; i++) printf("%d ",ans[i]);
return 0;
}
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the cipher is processed as:
- Convert all letters of the sentence to lowercase.
- Reverse each of the words of the sentence individually.
- Remove all the spaces in the sentence.
For example, when this cipher is applied to the sentence
Kira is childish and he hates losing
the resulting string is
ariksihsidlihcdnaehsetahgnisol
Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.
The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of nlowercase English letters — the ciphered text t.
The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.
Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.
30 ariksihsidlihcdnaehsetahgnisol 10 Kira hates is he losing death childish L and Note
Kira is childish and he hates losing
12 iherehtolleh 5 HI Ho there HeLLo hello
HI there HeLLo
In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.
题意:
Yash对自己的一段话加密:
1.将所有大写字母转成小写
2.将每个单词翻转
3.去除所有空格
现给出这段话中可能出现的一些单词,问这段话的原话是什么?
若有多种解输出任意一种
题解:
注意到单词数不超过1000000,考虑建立一棵trie
原话字符<=10000,那么从左到右for一遍尝试找解,又字符长度<=1000所以每个位置的查询向左1000位即可。tri可以以小写字符存储,找到存在的单词点输出对应位置原单词,降低编写难度
O(n*w)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1E4 + 10;
struct T{
int ch[26];
int END;
T () {
memset(ch,0,sizeof(ch));
END = 0;
}
}t[1000010];
int cnt,n,m,f[maxn],last[maxn];
char x[maxn],y[1010];
vector <char> v[maxn*10];
void Insert(int o,int pos,int len,int num)
{
for (; pos < len; pos++) {
int to;
if (y[pos] >= 'a') to = y[pos]-'a';
else to = y[pos]-'A';
if (!t[o].ch[to]) t[o].ch[to] = ++cnt;
o = t[o].ch[to];
}
t[o].END = num;
}
void solve(int pos)
{
int END = max(1,pos-999);
int o = 0;
for (int i = pos; i >= END; i--) {
o = t[o].ch[x[i]-'a'];
if (!o) break;
if ((f[i-1] || i == 1) && t[o].END) {
last[pos] = i;
f[pos] = t[o].END;
break;
}
}
}
void pri(int pos)
{
if (last[pos] != 1) pri(last[pos]-1);
int len = v[f[pos]].size();
for (int i = 0; i < len; i++) printf("%c",v[f[pos]][i]);
printf(" ");
}
int main()
{
#ifdef YZY
freopen("yzy.txt","r",stdin);
#endif
cin >> n;
scanf("%s",1+x);
cin >> m;
for (int i = 1; i <= m; i++) {
scanf("%s",&y);
int len = strlen(y);
Insert(0,0,len,i);
for (int j = 0; j < len; j++) v[i].push_back(y[j]);
}
for (int i = 1; i <= n; i++)
solve(i);
pri(n);
return 0;
}
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if
- the sequence consists of at least two elements
- f0 and f1 are arbitrary
- fn + 2 = fn + 1 + fn for all n ≥ 0.
You are given some sequence of integers a1, a2, ..., an. Your task is rearrange elements of this sequence in such a way that its longest possible prefix is Fibonacci-ish sequence.
The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence ai.
The second line contains n integers a1, a2, ..., an (|ai| ≤ 109).
Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.
3 1 2 -1
3
5 28 35 7 14 21
4
In the first sample, if we rearrange elements of the sequence as - 1, 2, 1, the whole sequence ai would be Fibonacci-ish.
In the second sample, the optimal way to rearrange elements is , , , , 28.
题意:
现有一个数组,从中任意选一些数构成一个斐波那契数列,问能够成的最长数列的长度是多少
题解:
一堆绝对值<=10^9的数用来构造斐波那契数列,虽然斐波那契数列增长不快,但是长度也不可能超过100,暴力枚举最开始的两个数,尝试能否构成即可
O(n^2)
用离散化存数的时候一开始没考虑到 f0 = f1的情形
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1E3 + 10;
typedef long long LL;
int n,cur = 1,ans = 2,num[maxn],a[maxn],f[maxn],now[maxn];
void solve(int a,int b)
{
int tot = 2;
for (int i = 1; i <= cur; i++) now[i] = 0;
++now[a]; ++now[b];
a = num[a]; b = num[b];
for (;;) {
LL x = 1LL*a+1LL*b;
if (x < -1000000000 || x > 1000000000) break;
int c = a+b;
int pos = lower_bound(num+1,num+cur+1,c)-num;
if (num[pos] != c || f[pos] == now[pos]) break;
++tot; ++now[pos];
a = b; b = c;
}
ans = max(ans,tot);
}
int main()
{
#ifdef YZY
freopen("yzy.txt","r",stdin);
#endif
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d",&a[i]);
num[i] = a[i];
}
sort(num+1,num+n+1);
for (int i = 2; i <= n; i++)
if (num[i] != num[i-1])
num[++cur] = num[i];
for (int i = 1; i <= cur; i++)
for (int j = 1; j <= n; j++)
if (num[i] == a[j])
++f[i];
for (int i = 1; i <= cur; i++)
for (int j = 1; j <= cur; j++)
if (i != j || f[i] > 1)
solve(i,j);
cout << ans;
return 0;
}