题意:
思路:
#include<bits/stdc++.h>
using namespace std;
int main(){
int s, t, x;
cin>>s>>t>>x;
if(s<t){
if(x>=s&&x<t)cout<<"Yes\n";
else cout<<"No\n";
}else{
if(x>=t&&x<s)cout<<"No\n";
else cout<<"Yes\n";
}
return 0;
}
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main(){
int n, s;
cin>>n>>s;
for(int i = 1; i <= n; i++){
cin>>a[i];
}
set<int>se;
int now = s;
for(int i = 1; i <= n; i++){
if(i!=1 && now==s)break;
se.insert(now);
now = a[now];
}
cout<<se.size()<<"\n";
return 0;
}
题意:
思路:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn], b[maxn];
bool cmp(int x, int y){return x>y;}
int main(){
int n, k; cin>>n>>k;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= 3; j++){
int x; cin>>x; a[i] += x;
}
b[i] = a[i];
}
sort(b+1,b+n+1,cmp);
for(int i = 1; i <= n; i++){
int p = lower_bound(b+1,b+n+1,a[i]+300,greater<int>())-b;
if(p<=k || a[i]+300>=1200)cout<<"Yes\n";
else cout<<"No\n";
// if(a[i]+300>=b[k])cout<<"Yes\n";
// else cout<<"No\n";
}
return 0;
}
题意:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = (1<<20)-1;
int fa[maxn+10];
void init(int n){for(int i = 0; i <= n; i++)fa[i]=i;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x, int y){x=find(x);y=find(y);if(x!=y)fa[x]=y;}
int count(int n){int cnt=0; for(int i = 1; i <= n; i++)if(fa[i]==i)cnt++;return cnt;}
LL v[maxn+10];
int main(){
init(maxn);
memset(v,-1,sizeof(v));
int q; cin>>q;
while(q--){
LL op, x; cin>>op>>x;
if(op==1){
int i = find(x&maxn);
v[i] = x;
fa[i] = find((i+1)&maxn);
}else{
cout<<v[x&maxn]<<"\n";
}
}
return 0;
}