#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;intmain(){int num, k =0;while(cin >> num){for(int i =7; i >=0; i --)if(num >> i &1)
cout <<"*";else
cout <<' ';
k ++;if(k ==2){
k =0;puts("");}}return0;}
#include<iostream>#include<cstring>#include<algorithm>#include<cmath>usingnamespace std;typedeflonglong LL;intmain(){
LL res =pow(9,9);
cout << res << endl;return0;}
测试次数
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>usingnamespace std;constint N =10010;int n;int f[4][N];intmain(){//scanf("%d", &n);
n =1000;memset(f,0x3f3f3f,sizeof f);for(int i =0; i <= n; i ++)
f[1][i]= i;for(int i =2; i <=3; i ++){
f[i][0]=0;for(int j =1; j <= n; j ++)for(int k =1; k <= j; k ++){
f[i][j]=min(f[i][j],max(f[i -1][k -1], f[i][j - k])+1);}}printf("%d\n", f[3][n]);return0;}
快速排序
#include<stdio.h>intquick_select(int a[],int l,int r,int k){int p =rand()%(r - l +1)+ l;int x = a[p];{int t = a[p]; a[p]= a[r]; a[r]= t;}int i = l, j = r;while(i < j){while(i < j && a[i]< x) i++;if(i < j){
a[j]= a[i];
j--;}while(i < j && a[j]> x) j--;if(i < j){
a[i]= a[j];
i++;}}
a[i]= x;
p = i;if(i - l +1== k)return a[i];if(i - l +1< k)returnquick_select(a, i, r, k -(i - l +1));//填空elsereturnquick_select(a, l, i -1, k);}intmain(){int a[100];int n;scanf("%d %d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);printf("%d\n",quick_select(a,0, n-1,5));return0;}
递增三元组
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;typedeflonglong LL;constint N =100010;int n;
LL res =0;int a[N], b[N], c[N];intmain(){int l =0, r =0;scanf("%d",&n);for(int i =0; i < n; i ++)scanf("%d",&a[i]);for(int i =0; i < n; i ++)scanf("%d",&b[i]);for(int i =0; i < n; i ++)scanf("%d",&c[i]);sort(a, a + n);sort(b, b + n);sort(c, c + n);for(int i =0; i < n; i ++){while(l < n && a[l]< b[i]) l ++;while(r < n && c[r]<= b[i]) r ++;
res +=(LL)l *(n - r);}printf("%lld\n", res);return0;}
螺旋折线
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;typedeflonglong LL;intmain(){int x, y;
cin >> x >> y;int n;if(abs(x)<= y){
n = y;
cout <<(LL)(2* n -1)*2* n + x -(-n)<< endl;}elseif(abs(y)<= x){
n = x;
cout <<(LL)(2* n)*(2* n)+ n - y << endl;}elseif(abs(x)<=abs(y)+1&& y <0){
n =abs(y);
cout <<(LL)(2* n)*(2* n +1)+ n - x << endl;}else{
n =abs(x);
cout <<(LL)(2* n -1)*(2* n -1)+ y -(-n +1)<< endl;}return0;}
日志统计
#include<iostream>#include<cstring>#include<algorithm>#definexfirst#defineysecondusingnamespace std;constint N =100010;typedef pair<int,int> PII;
PII logs[N];int cnt[N];bool st[N];int n, d, k;intmain(){scanf("%d%d%d",&n,&d,&k);for(int i =0; i < n; i ++){scanf("%d%d",&logs[i].x,&logs[i].y);}sort(logs, logs + n);for(int i =0, j =0; i < n; i ++){int id = logs[i].y;
cnt[id]++;while(logs[i].x - logs[j].x >= d){
cnt[logs[j].y]--;
j ++;}if(cnt[id]>= k) st[id]=true;}for(int i =0; i < N; i ++)if(st[i])printf("%d\n", i);return0;}
全球变暖
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;constint N =1010;char g[N][N];int cnt, sum, n;bool st[N][N];int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};voiddfs(int x,int y){
st[x][y]=true;
sum ++;bool flag =false;for(int i =0; i <4; i ++){int sx = x + dx[i], sy = y + dy[i];if(sx <0|| sx >= n || sy <0|| sy >= n)continue;if(g[sx][sy]=='.'){
flag =true;continue;}if(st[sx][sy])continue;dfs(sx, sy);}if(flag) cnt ++;}intmain(){scanf("%d",&n);for(int i =0; i < n; i ++)scanf("%s", g[i]);int res =0;for(int i =0; i < n; i ++)for(int j =0; j < n; j ++)if(g[i][j]=='#'&&!st[i][j]){
sum =0, cnt =0;dfs(i, j);if(sum == cnt) res ++;}
cout << res << endl;return0;}
乘积最大
#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;typedeflonglong LL;constint N =100010;constint mod =1000000009;int n, k;
LL a[N];intmain(){scanf("%d%d",&n,&k);for(int i =0; i < n; i ++)scanf("%lld",&a[i]);sort(a, a + n);
LL res =1;int l =0, r = n -1;int sign =1;if(k &1){
res *= a[r];
k --;
r --;if(res <0) sign =-1;}while(k){
LL x = a[l]* a[l +1], y = a[r]* a[r -1];if(x * sign > y * sign){
res = x % mod * res % mod;
l +=2;}else{
res = y % mod * res % mod;
r -=2;}
k -=2;}printf("%lld\n", res);return0;}