第十二届蓝桥杯(第二场)编程题 C++ B组
作者:互联网
特殊年份
https://www.acwing.com/problem/content/3499/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
string s[5];
int ans;
int fun(string s){
if(s[0]==s[2] && s[3]-s[1]==1){
return 1;
}
return 0;
}
int main(){
for(int i=0;i<5;i++){
cin>>s[i];
if(fun(s[i])) ans++;
}
cout<<ans<<endl;
return 0;
}
// freopen("testdata.in", "r", stdin);
小平方
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
int n;
int temp;
int ans;
int main(){
cin>>n;
temp=n/2+1;
for(int i=1;i<=n-1;i++){
if(i*i%n*2<n){
ans++;
}
}
cout<<ans;
return 0;
}
// freopen("testdata.in", "r", stdin);
完全平方数
https://www.acwing.com/problem/content/3494/
完全平方数=两个数的乘积 因此有质因数次数是偶数的规律
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<unordered_map>
using namespace std;
typedef long long LL;
int main(){
LL n;
cin>>n;
LL res=1;
for(LL i=2;i*i<=n;i++){
if(n%i==0){
int s=0;
while(n%i==0){
s++;
n/=i;
}
if(s%2){//该质因数是奇数次数,需要乘上一个
res*=i;
}
}
}
if(n>1) res*=n;
cout<<res;
return 0;
}
// freopen("testdata.in", "r", stdin);
负载均衡
https://www.acwing.com/problem/content/3495/
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 200010;
int n, m;
int s[N];
priority_queue<PII, vector<PII>, greater<PII>> q[N];//小根堆
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ ) scanf("%d", &s[i]);
while (m -- )
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
while (q[b].size() && q[b].top().x <= a)//删除已完成的任务
{
s[b] += q[b].top().y;
q[b].pop();
}
if (s[b] < d) puts("-1");
else
{
q[b].push({a + c, d});
s[b] -= d;
printf("%d\n", s[b]);
}
}
return 0;
}
标签:第二场,typedef,int,LL,namespace,C++,蓝桥,long,include 来源: https://www.cnblogs.com/OfflineBoy/p/14768674.html