- C20250038's blog
剽窃代码
- 2023-7-25 14:17:32 @
P1540
#include<bits/stdc++.h>
using namespace std;
bool v[1001];
queue<int> q;
int n,m;
int ans = 0;
int main() {
scanf("%d%d",&n,&m);
while (m--) {
int x;
cin>>x;
if (v[x]) continue;
v[x]=1;
q.push(x);
ans++;
if (q.size()>n) {
int y = q.front();
q.pop();
v[y]=0;
}
}
cout<<ans<<endl;
return 0;
}
P3378
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n;
int h[maxn];
int cnt = 0;//cnt表示元素个数
void ins(int x) {
h[++cnt]=x;//将新入的数据放入尾部
int rt = cnt;
while (rt!=1&&h[rt]<h[rt/2]) {
swap(h[rt],h[rt/2]);//交换
rt/=2;
}
}
void del() {
h[1]=h[cnt--];
//向下调整
int rt = 1;
while (1) {
int ls = rt*2;
int rs = ls+1,s=ls;
if (s>cnt) break;
if (rs<=cnt) {
if (h[ls]>h[rs]) s = rs;
}
if (h[rt]>h[s]) {
swap(h[rt],h[s]);
rt = s;
}else break;
}
}
int main() {
cin>>n;
while (n--){
int op;
cin>>op;
if (op==1) {
int x;
cin>>x;
ins(x);
}
if (op==2) {
cout<<h[1]<<endl;
}
if (op==3) {
del();
}
}
return 0;
}
P1090
#include<bits/stdc++.h>
using namespace std;
int n;
int a[10001],b[20001],c[10001];
priority_queue<int,vector<int>,greater<int> > q;//求最小值的队列
priority_queue<int> dq;//求最大值的队列
int main() {
cin>>n;
for (int i = 1; i <= n ; i ++ ) {
cin>>a[i];
b[a[i]]++;
}
int k = 0;
for (int i = 0 ; i <= 20000 ; i ++ ) {
while (b[i]--) {
a[++k]=i;
}
}
//cnt 表示c数组当前最后一个元素 l表示c数组当前第一个元素下标
int j = 1,cnt = 0 ,l = 1;//表示a数组里边从小到大考虑到了第j个数
int ans = 0 ;
for (int i = 1; i < n ; i ++ ) {
int sum = 1e9,id;
//全部从a里边找
if (j<n) {
sum = min(sum,a[j]+a[j+1]);
id = 1;
}
//全部从b来的
if (l+1<=cnt) {
if (sum>c[l]+c[l+1]) {
sum = c[l]+c[l+1];
id = 2;
}
}
//一个从a来一个从b来
if(j<=n&&l<=cnt) {
if (sum>c[l]+a[j]) {
sum = a[j]+c[l];
id = 3;
}
}
if (id == 1) {
c[++cnt]=a[j]+a[j+1];
j+=2;
}
if (id == 2) {
c[++cnt]=c[l]+c[l+1];
l+=2;
}
if (id == 3) {
c[++cnt]=sum;
l++,j++;
}
ans+=sum;
}
cout<<ans<<endl;
return 0;
}
P1168
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q1;//默认的大根堆
priority_queue<int,vector<int>,greater<int> > q2;//小根堆
//q.top()取堆顶
//q.pop()删除堆顶
//q.push(x)x插入堆
//q.size() 堆的元素个数
int n;
int main() {
cin>>n;
int x;
cin>>x;
q1.push(x);
cout<<x<<endl;
for (int i = 2; i <= n ; i ++ ) {
cin>>x;
if (x>q1.top()) q2.push(x);
else q1.push(x);
while (abs(int(q1.size())-int(q2.size()))>1) {
if (q1.size()>q2.size()) {
q2.push(q1.top());
q1.pop();
}else {
q1.push(q2.top());
q2.pop();
}
}
if (i%2==1) {
if (q1.size()>q2.size()) cout<<q1.top()<<endl;
else cout<<q2.top()<<endl;
}
}
return 0;
}
P1638
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n,m,ans = maxn,ans_i,ans_j;
int a[maxn],v[maxn],sum=0;
int main() {
cin>>n>>m;
for (int i = 1; i <= n ; i ++ ) {
cin>>a[i];
}
int r = 1;
for (int l = 1 ; l <= n ; l ++ ) {
while (r<=n) {
v[a[r]]++;
if (v[a[r]]==1) sum++;
if (sum==m) {
if (r-l+1<ans) {
ans = r-l+1;
ans_i = l;
ans_j = r;
}
break;
}
r++;
}
v[a[l]]--;
if (v[a[l]]==0) sum--;
}
cout<<ans_i<<' '<<ans_j<<endl;
return 0;
}
B2058
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,G,S,B;
cin>>n;
G=S=B=0;
for (int i = 1; i <= n ; i ++ ) {
int a,b,c;
cin>>a>>b>>c;
G+=a;S+=b;B+=c;
}
cout<<G<<' '<<S<<' '<<B<<' '<<G+S+B<<endl;
return 0;
}
P2058
#include<bits/stdc++.h>
using namespace std;
//刘昕苡太强拉
int n,num;
int cnt[100010],T[100010];//c[i] 表示第i个国家的国籍人数有多少
queue<int> q;
queue<int> t;
int ans = 0;
int main(){
cin>>n;
for (int i = 1; i <= n ; i ++ ) {
cin >> T[i]>> num;
while(t.size()&&t.front()<=T[i]-86400){
t.pop();
cnt[q.front()]--;
if (!cnt[q.front()]) ans--;
q.pop();
}
for(int j = 1;j <= num; j ++){
int k;
cin>>k;
q.push(k);
if (!cnt[k]) ans++;
cnt[k]++;
t.push(T[i]);
}
cout<<ans<<endl;
}
return 0;
}