标签:scanf ges sort using style cin watch tor iostream
A.Oath of the Night‘s Watch
简单的排序
1 #include <iostream> 2 //#include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 using namespace std; 11 typedef long long ll; 12 typedef unsigned long long ull; 13 const int MAX=1e5+5; 14 int a[MAX]; 15 int main() 16 { 17 int n; 18 int l,r; 19 scanf("%d",&n); 20 for(int i=0;i<n;i++) 21 { 22 scanf("%d",&a[i]); 23 } 24 sort(a,a+n); 25 if(a[0]==a[n-1]) 26 printf("0\n"); 27 else 28 { 29 l=0;r=n-1; 30 while(a[l+1]==a[l]) 31 l++; 32 while(a[r-1]==a[r]) 33 r--; 34 printf("%d\n",max(0,r-l-1)); 35 } 36 }
B.Code For 1
分析n的二进制各位是0还是1。用数组a记录,设a的下标到x。对于操作后的第i个数,设i的因数2的幂次最大为z,i的值等于a[x-z]
1 #include <iostream> 2 //#include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 using namespace std; 11 typedef long long ll; 12 typedef unsigned long long ull; 13 ll n; 14 ll l,r; 15 int a[100]; 16 int main() 17 { 18 cin>>n>>l>>r; 19 ll i; 20 ll cnt,j,an=0,wei; 21 for(i=0;n;i++) 22 { 23 a[i]=n%2; 24 n/=2; 25 } 26 wei=i-1; 27 // printf("wei=%lld\n",wei); 28 for(i=l;i<=r;i++) 29 { 30 cnt=0; 31 j=i; 32 while(j%2==0) 33 { 34 cnt++; 35 j/=2; 36 } 37 // printf("%d\n",cnt); 38 if(a[wei-cnt]) 39 an++; 40 } 41 cout<<an<<"\n"; 42 43 }
C.Jon Snow and his Favourite Number
经历若干次这样的操作后就会稳定下来。只需要模拟整个过程,每次循环的末尾判断是否稳定下来即可。
1 #include <iostream> 2 //#include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 using namespace std; 11 typedef long long ll; 12 typedef unsigned long long ull; 13 const int MAX=1e5+5; 14 int n,k,x; 15 int a[MAX]; 16 int xiao[MAX],da[MAX]; 17 int main() 18 { 19 cin>>n>>k>>x; 20 for(int i=0;i<n;i++) 21 cin>>a[i]; 22 sort(a,a+n); 23 // if(k%2==1) 24 for(int j=0;j<k;j++) 25 { 26 for(int i=0;i<n;i++) 27 if(i%2==0) 28 a[i]=a[i]^x; 29 // } 30 sort(a,a+n); 31 xiao[j]=a[0];da[j]=da[n-1]; 32 if(j>=2&&xiao[j]==xiao[j-1]&xiao[j]==xiao[j-2]&&da[j]==da[j-1]&&da[j]==da[j-2]) 33 break; 34 } 35 printf("%d %d\n",a[n-1],a[0]); 36 37 }
Codeforces Round #399 (Div. 1 + Div. 2, combined) 解题报告
标签:scanf ges sort using style cin watch tor iostream
原文地址:http://www.cnblogs.com/quintessence/p/6423173.html