版权声明:本文为博主原创文章,未经博主允许也可以转载。 https://blog.csdn.net/FrankAx/article/details/82908995
Code:
#include <bits/stdc++.h>
using namespace std;
int a[205] ;
int b[205] ;
map<int,int>mp;
int main(){
int n , d ;
int tot = 0 ;
cin >> n >> d ;
for( int i = 0 ; i < n ; i++ ){
cin >> a[i] ;
b[tot++] = a[i] - d ;
b[tot++] = a[i] + d ;
}
int res = 0 ;
for( int i = 0 ; i < tot ; i++ ){
if( mp[b[i]] ) continue ;
mp[b[i]] = 1 ;
int f = 1 ;
for( int j = 0 ; j < n ; j++ ){
if( abs( b[i] - a[j] ) < d ){
f = 0 ; break ;
}
}
if( f ) res ++ ;
}
cout << res << endl ;
return 0 ;
}
B
思路:跟区间没有关系,哦01间隔输出即可
Code:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n , m ;
cin >> n >> m ;
for( int i = 0 ; i < n ; i++ ){
cout << i % 2 ;
}cout << endl;
return 0 ;
}
C
思路:倒序维护下就行了
Code:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int AX = 1e5 + 66 ;
int a[AX];
map<int,int>r;
map<int,int>n_r;
int main(){
int n ;
cin >> n ;
for( int i = 0 ; i < n ; i++ ){
cin >> a[i] ;
}
for( int i = n - 1 ; i >= 0 ; i-- ){
if( i == n - 1 ){
r[a[i]] = 1 ;
n_r[i] ++ ; continue ;
}
if( !r[a[i]] ){
r[a[i]] = 1 ;
n_r[i] = n_r[i+1] + 1 ;
}else n_r[i] = n_r[i+1] ;
}
map<int,int>mp ;
LL res = 0LL;
for( int i = 0 ; i < n - 1 ; i++ ){
if( mp[a[i]] ) continue ;
mp[a[i]] = 1 ;
res += n_r[i+1] ;
}
cout << res << endl;
return 0 ;
}
思路:这题牛b啊,1 , 2 , 3…这些数都是以菱形包围着0,每个数i个数如果完整就是4i个,那么0位置的横坐标x=最小的不满足4i个的数。
最大值mx = n + m - x(0位置) - y (0位置)。
然后检查整个图。。
Code:
#include <bits/stdc++.h>
using namespace std;
const int AX = 1e6 + 66;
int a[AX] ;
int t ;
int x , y , n , m ;
int mp[AX];
bool check(){
memset( mp , 0 , sizeof(mp) ) ;
for( int i = 1 ; i <= n ; i++ ){
for( int j = 1 ; j <= m ; j++ ){
mp[abs(i-x)+abs(j-y)] ++ ;
}
}
for( int i = 0 ; i < t ; i++ ){
if( mp[i] != a[i] ) return false;
}
return true ;
}
int main(){
scanf("%d",&t);
int v ;
int mx = 0 ;
for( int i = 0 ; i < t ; i++ ){
scanf("%d",&v) ;
mx = max( mx , v ) ;
a[v] ++ ;
}
for( int i = 1 ; i <= t ; i++ ){
if( a[i] != 4 * i ){
x = i ; break;
}
}
for( n = 1 ; n <= t ; n++ ){
if( !( t % n ) ){
m = t / n ;
y = n + m - x - mx ;
if( check() ){
return 0*printf("%d %d\n%d %d",n,m,x,y);
}
}
}
printf("-1\n");
return 0 ;
}