1223:An Easy Problem
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n){
if(n==0) break;
int cnt1=0,tmp=n;
while(n!=0){
if(n&1) cnt1++;
n>>=1;
}
while(1){
int cnt2=0;
tmp+=1;
n=tmp;
while(n!=0){
if(n&1) cnt2++;
n>>=1;
}
if(cnt2==cnt1){
cout<<tmp<<endl;
break;
}
}
}
return 0;
}
1324:【例6.6】整数区间
#include<bits/stdc++.h>
using namespace std;
const int maxsize=10001;
struct node{
int a,b;
};
node arr[maxsize];
int n,m,sum=0;
bool cmp(node t1,node t2){
if(t1.b!=t2.b){
return t1.b<t2.b;
}else{
return t1.a<t2.a;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>arr[i].a>>arr[i].b;
sort(arr+1,arr+1+n,cmp);
int tmp=-1,ans=0;
for(int i=1;i<=n;i++){
if(tmp>=arr[i].a) continue;
tmp=arr[i].b;
ans++;
}
cout<<ans<<endl;
return 0;
}