我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。 ----喻言
链接:https://ac.nowcoder.com/acm/problem/15809
来源:牛客网
题目描述
对于k进制数x,定义d(x)为x的各数位的和的k进制表示,如果结果超过一位,则继续重复执行各数位求和操作,直至结果为1位。
比如说,在7进制下,d(35047)=d((3+5+0+4)7)=d(157)=d((1+5)7)=d(67)=6
定义x为幸运的,当且仅当d(x) = b;
现在给定k进制下的n个数位a1 a2 an,问其中有多少子串组成的数字是幸运的。
输入描述:
第一行三个整数k,b,n(2 <= k <= 1,000,000,000, 0 <= b < k, 1 <= n <= 100,000)。 第二行n个整数满足0 <= ai < k。
输出描述:
输出一个整数表示幸运的子串数。
示例1
输入
复制
10 5 6 3 2 0 5 6 1
输出
复制
5
说明
3 2 3 2 0 0 5 5 2 0 5 6 1 是幸运的。
示例2
输入
复制
7 6 4 3 5 0 4
输出
复制
1
示例3
输入
复制
257 0 3 0 0 256
输出
复制
3
#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=100000+10;
int const mod=1e9+7;
const int maxn=1e5+5;
int k,b,n,yx=1,ls,a[maxn];
ll jg;
map<int,int> mp;
int main()
{
scanf("%d%d%d",&k,&b,&n);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
if(a[i])
yx=i+1;
else
jg+=i-yx+1;
}
if(!b){
printf("%lld\n",jg);
return 0;
}
if(b==k-1){
jg=-jg;
b=0;
}
else
jg=0;
mp[0]=1;
for(int i=1; i<=n; i++){
(ls+=a[i])%=k-1;
jg+=mp[(ls-b+k-1)%(k-1)];
mp[ls]++;
}
printf("%lld\n",jg);
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15761
来源:牛客网
题目描述
现在萌新要乘船度过一条河,这条河宽为s米。
现已知船相对于水的速度为v1,水流的速度为v2。
由于萌新想到达起点的正对岸,所以他会一直调整船行驶的方向朝向正对岸。
你的任务是计算萌新将用多少时间度过这条河;若他不能到达起点的正对岸,输出“Infinity”。
输入描述:
第一行输入一个整数n,表示测试用例数; 接下来n行,每行输入三个整数s、v1、v2。 其中,1≤n≤1000,0≤s≤100, 0≤v1,v2≤100。
输出描述:
输出一个实数,你的任务是计算萌新将用多少时间度过这条河(保留10位小数);若他不能到达起点的正对岸,输出“Infinity”。
示例1
输入
复制
3 2 2 2 2 4 3 5 6 5
输出
复制
Infinity 1.1428571429 2.7272727273
#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=100000+10;
int const mod=1e9+7;
const int maxn=2e6+10;
int t;
int main() {
scanf("%d",&t);
while(t--){
int s,v1,v2;
scanf("%d%d%d",&s,&v1,&v2);
if(s==0)
printf("%.10lf\n",0.0);
else if(v1<=v2)
printf("Infinity\n");
else{
double ans=(v1*s)*1.0/(v1*v1-v2*v2);
printf("%.10lf\n",ans);
}
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/15760
来源:牛客网
题目描述
2018年萌新刚升为队长,于是带领校队的n名队员一起去郊游,他选定的地点与学校的距离为l米。
为了更快达到目的地,萌新计算了经费后为大家租赁了一辆限乘k人的车,队员们都非常不满,但对于萌新队长敢怒不敢言。
现已知队员走路的速度为v1,车的速度为v2,每位队员只能上车一次。
你的任务是帮助萌新确定到达目的地所用的时间(保留10位小数,考虑上车下车、车掉头时间不计)
输入描述:
第一行输入一个整数m,代表m组数据。 接下来m行,输入5个正整数n,l,v1,v2,k。 其中1≤m≤1000,1≤n≤10000, 1≤l≤109, 1≤v1<v2≤109, 1≤k≤n
输出描述:
输出一行,为一个实数。代表萌新确定到达目的地所用的时间(保留10位小数,考虑上车下车、车掉头时间不计)
示例1
输入
复制
1 3 6 1 2 1
输出
复制
4.7142857143
#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=100000+10;
int const mod=1e9+7;
const int maxn=2e6+10;
int m, n,l,v1,v2,k,p;
int main()
{
scanf("%d" , &m);
while(m--)
{
scanf("%d%d%d%d%d" , &n, &l, &v1, &v2, &k);
if(n%k==0)
p=n/k;
else
p=n/k+1;
double x=(double)l*(v1+v2)/(v1+v2+2*v1*(p-1));
double t=(double)x/v2+(l*1.0-x)/v1;
printf("%.10f\n" , t);
}
return 0;
}