Codeforces Round #399 (A,B,C)
/*
Divide by Zero 2017 and Codeforces Round #399
Oath of the Night's Watch
時間: 2017/02/21
題意:在n個數中尋找比最大值小比最小值大的數有幾個。
題解
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define N 100010
#define INF 0x3f3f3f3f
int a[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
int minn = INF, maxn = -INF;
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
minn = min(a[i],minn);
maxn = max(a[i],maxn);
}
int ans = n;
for(int i = 0; i < n; i++)
{
if(minn == a[i])
ans--;
else if(maxn == a[i])
ans--;
}
printf("%d\n",ans);
}
return 0;
}
/*
Divide by Zero 2017 and Codeforces Round #399
Code For 1
時間: 2017/02/21
題意:將一個數2^50,分半劃分成0,1後,問在l,r區間1的數量
題解:
發現1,0出現的位置是和n的二進位制有關,具體:滿足i%(2^xi)==0的最大xi,第i個位置的數就是二進位制從後往前的第xi個二進位制值。
注意 位運算1<<n 在n較大時時間花費巨大
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define LL long long
const int N = 110;
const int INF = 0x3f3f3f3f;
int a[N];
int main()
{
LL n,l,r;
while(cin>>n>>l>>r)
{
vector<int> bits;
while(n)
{
bits.push_back(n&1);
n /= 2;
}
reverse(bits.begin(),bits.end());
int sum = 0;
for(long long i = l; i <= r; i++)
{
int j = 0;
long long x = 1;
while(i%x == 0)
{
x <<= 1;
j++;
}
if(bits.size() <= j-1)
sum += 0;
else
sum += bits[j-1];
//printf("%d\n",sum);
}
printf("%d\n",sum);
}
return 0;
}
/*
Divide by Zero 2017 and Codeforces Round #399
Jon Snow and his Favourite Number
時間: 2017/02/21
題意:將n個數的集合處理k次,每次處理:先從小到大排序,然後奇數位於x異或,找到最後最大和最小的。
題解:參考了大神們的程式碼,瞭解到:既然要求從大到小,並且數和x的範圍是1e3,異或後最大也就1024,那麼開個陣列a[i]代表當前值為i的數有幾個。
從中做文章,從小到大處理出改變數的個數和當前處理後處在奇數位還是偶數位。
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define N 1025
#define INF 0x3f3f3f3f
int a[N],b[N];
int main()
{
int n,k,x;
while(~scanf("%d%d%d",&n,&k,&x))
{
int f;
for(int i = 0; i < n; i++)
{
scanf("%d", &f);
a[f]++;
}
for(int i = 0; i < k; i++)
{
for(int j = 0; j < N; j++)
{
b[j] = a[j];
a[j] = 0;
}
int ge,odd = 0;
for(int j = 0; j < N; j++)
{
ge = (b[j]+1-odd)/2;// 要改變的個數
a[j^x] += ge;
a[j] += b[j]-ge;
odd = (b[j]+odd)%2;// 當前的處於位數的奇偶
}
}
int mx = 0, mn = 1024;
for(int i = 0; i < 1024; i++)
{
if(a[i])
{
mx = max(mx,i);
mn = min(mn,i);
}
}
printf("%d %d\n",mx,mn);
}
return 0;
}
相關文章
- Codeforces Round 840題解(A、B、C)
- codeforces round 961題解(A、B、C)
- Codeforces Round 949題解(A、B、C、D)
- Codeforces Round #290 (Div. 2) A,B,C,D
- Codeforces Round #288 (Div. 2) A,B,C,D,E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #280 (Div. 2 A,B,C,D,E)
- Codeforces Round 977 (Div. 2)(B-C2)
- Codeforces Round 976 (Div. 2) and Divide By Zero 9.0(A,B,C)IDE
- Codeforces Round #448 (Div. 2)B
- Codeforces Round #450 (Div. 2) B
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Codeforces Testing Round #10 B. Balancer
- Codeforces Round #251 (Div. 2) A/B/D
- Codeforces Round #469 C A. Zebras
- 【Codeforces Round #499 (Div. 1) B】Rocket
- Codeforces Round #362 (Div. 2) B 模擬
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #325 (Div. 2) B 遞推
- Codeforces Round #245 (Div. 2) B - Balls GameGAM
- Codeforces Round 934 2D/1B
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
- BestCoder Round #20 B,C
- Codeforces Round #470 div2 C
- Codeforces Round #453 (Div. 2) C
- Codeforces Round #452 (Div. 2) C
- Codeforces Round 973 (Div. 2) C
- Codeforces Round 972 (Div. 2) C
- Codeforces Round 982 (Div. 2)(A~C)
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #361 (Div. 2) B BFS最短路
- Codeforces Round #323 (Div. 2) B 模擬
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #247 (Div. 2) B - Shower Line
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI