我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。 ----喻言
链接:https://ac.nowcoder.com/acm/problem/15868
来源:牛客网
题目描述
It’s universally acknowledged that there’re innumerable trees in the campus of HUST.
One day you find an endless forest consisting of magic trees. The forest can be described in such a strange way: initially you know N trees with the magic power a1,…,an. Then for every (i,j) (i can be equal to j) one tree with the magic power ai-aj and one tree with the magic power ai+aj will appear in the forest, then you know there will be 3N trees with the magic power a1,…,a3na_1,…,a_{3n}a1,…,a3n. This process can be done repeatedly, so you know that the infinite forest contains innumerable trees. What you want to know is if there’s a tree with the magic power X.
输入描述:
The first line contains two integer N0 and M(1≤N0,M≤103), the number of trees you initially know and the number of queries. The next line are N0 integer a1,…,an (1≤ai≤105) as described above. Then followed M lines with each line a integer X(1≤X≤105) as described above.
输出描述:
For each query: If there is no such a tree print “NO”. Otherwise find a solution that X=∑ai×ki and print N integer ki, which should be no greater than 64-bits integer in a line. If there are multiple solutions, print any of them. Warning: do not print extra space or empty line!
示例1
输入
复制
2 3 2 6 4 10 11
输出
复制
2 0 2 1 NO
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1010;
int const mod=1e9+7;
const int maxn=1e5+10;
ll a[N],b[N],x,y,d;
int n,m;
ll extgcd(ll a,ll b,ll &x,ll &y){
if(!b){
x=1;
y=0;
return a;
}
d=extgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
void js(int ls){
d=extgcd(d,a[ls],x,y);
b[ls]=y;
for(int i=0;i<ls;i++)
b[i]*=x;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
b[0]=1;
d=a[0];
for(int i=1;i<n;i++)
js(i);
while(m--){
scanf("%lld",&y);
x=y%d;
if(x)
printf("NO\n");
else{
x=y/d;
for(int i=0;i<n-1;i++)
printf("%lld ",b[i]*x);
printf("%lld\n",b[n-1]*x);
}
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15870
来源:牛客网
题目描述
给出两个串s和x
定义s中的某一位i为好的位置,当且仅当存在s的子序列y=sk1sk2....sk∣x∣(1<=k1<k2<...<k∣x∣<=∣s∣)y=s_{k_{1}}s_{k_{2}}....s_{k_{|x|}}(1 <= k_{1} < k_{2} < ... < k_{|x|} <= |s|)y=sk1sk2....sk∣x∣(1<=k1<k2<...<k∣x∣<=∣s∣) 满足y=x且存在j使得i=kj成立。
问s中是否所有的位置都是好的位置。
输入描述:
一行两个字符串s,x,这两个串均由小写字母构成。 1 <= |s|, |x| <= 200000
输出描述:
Yes表示是。 No表示不是。
示例1
输入
复制
abab ab
输出
复制
Yes
示例2
输入
复制
abacaba aba
输出
复制
No
示例3
输入
复制
abc ba
输出
复制
No
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1010;
int const mod=1e9+7;
const int maxn=1e5+10;
int nx[200100];
vector<int>v;
void getnx(string s)
{
int i=0,j=-1;
nx[0]=-1;
while(i<s.size()){
if(j==-1||s[i]==s[j]){
i++;
j++;
nx[i]=j;
}
else
j=nx[j];
}
}
int kmp(string s,string p)
{
getnx(p);
int i=0,j=0,ct=0;
while(i<s.size()){
if(j==-1||s[i]==p[j]){
i++;
j++;
}
else
j=nx[j];
if(j==p.size()){
ct++;
j=nx[j];
v.push_back(i);
}
}
return ct;
}
int main()
{
string a,b;
cin>>a>>b;
int ls=kmp(a,b);
if(ls*b.size()>=a.size()){
for(int i=1;i<v.size();i++){
if(v[i]-v[i-1]>b.size()){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15867
来源:牛客网
题目描述
Tony and Macle are good friends. One day they joined a birthday party together. Fortunately, they got the opportunity to have dinner with the princess, but only one person had the chance. So they decided to play a game to decide who could have dinner with the princess.
The rules of the game are very simple. At first, there are n sticks. Each of exactly m meters in length. Each person takes turns. For one move the player chooses just one stick and cut it into several equal length sticks, and the length of each stick is an integer and no less than k. Each resulting part is also a stick which can be chosen in the future. The player who can't make a move loses the game ,thus the other one win.
Macle make the first move.
输入描述:
the first line contains tree integer n,m,k(1 <= n,m,k <= 109)
输出描述:
print 'Macle' if Macle wins or 'Tony' if Tony wins,you should print everything without quotes.
示例1
输入
复制
1 15 4
输出
复制
Macle
示例2
输入
复制
4 9 5
输出
复制
Tony
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1e5+10;
int const mod=1e9+7;
const int maxn=1e5+10;
int n,m,k;
int main(){
while(cin>>n>>m>>k){
int fg=0;
for(int i=2;i<=(int)sqrt(m);i++)
if(m%i==0){
int j=m/i;
if(j>=k){
fg=1;
break;
}
}
if(k==1&&m!=1)
fg=1;
if(fg&&(n%2==1))
cout<<"Macle"<<endl;
else
cout<<"Tony"<<endl;
}
return 0;
}