牛牛算数
class Solution {
public:
/**
* 返回一个数字表示输出计算n个数字和的最小花费的时间。
* @param n int整型 表示有n个数。
* @param c int整型 参数c
* @param a int整型vector ai表示第i个数的大小
* @return long长整型
*/
long long solve(int n, int c, vector<int>& a) {
// write code here
long long ans=0;
priority_queue<long long ,vector<long long >,greater<long long > > h;
for (int i=0; i<n; i++)
{
h.push(a[i]);
}
long long x,y;
for (int i=1; i<n; i++)
{
x=h.top(),h.pop();
y=h.top(),h.pop();
ans+=(x+y); h.push(x+y);
}
ans=ans*(long long )c;
return ans;
}
};
怕npy的牛牛
class Solution {
public:
/**
* 返回符合题意的最长的子串长度
* @param x string字符串
* @return int整型
*/
int Maximumlength(string x) {
// write code here
int l=-1,r=-1;
int maxn=0,flag1=0,flag2=0,flag3=0;
int n=x.size();
while(1)
{
while(r<n)
{
r++;
if(x[r]=='n')flag1++;
if(x[r]=='p')flag2++;
if(x[r]=='y')flag3++;
if(flag1&&flag2&&flag3)break;
}
maxn=max(maxn,r-l-1);
if(r==n)break;
while(l<n)
{
l++;
if(x[l]=='n')flag1--;
if(x[l]=='p')flag2--;
if(x[l]=='y')flag3--;
if(flag1==0||flag2==0||flag3==0)break;
}
}
return maxn;
}
};
中位因数和
const int mod = 998244353;
long long f[1000010];
class Solution {
public:
/**
*
* @param x int整型 给定的x
* @return int整型
*/
int sum(int x) {
// write code here
for(int i = 1; i <= 1000000; i ++)
for(long long j = i; j * i <= 1000000; j ++)
f[i * j] = (i + j) / 2;
for(int i = 1; i <= 1000000; i ++)
f[i] = (f[i] + f[i - 1]) % mod;
return f[x];
}
};