18537231688

355

zhr05

zombotany
D.devil

18537231688
4个月前
#include <bits/stdc++.h>

using namespace std;

struct sec {
int l, r;
};

bool comp(sec a, sec b) {
return a.r < b.r;
}
sec s[100005];

int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i].l >> s[i].r;
}
sort(s, s + n, comp);
int tmp;
int cnt = 1;
for (int i = 0; i < n; ++i) {
if (i == 0) tmp = s[i].r;
else if (s[i].l <= tmp) continue;
else cnt++, tmp = s[i].r;
}
cout << cnt << endl;
return 0;
}


18537231688
4个月前
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

struct sec{
int l, r;
};
bool comp(sec a, sec b) {
return a.r < b.r;
}

int dot[(int)1e5 + 5];
int cnt = 0;

int main(void) {

sec s[N];

int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i].l >> s[i].r;
}
sort(s, s + n, comp);
for (int i = 0; i < n; ++i) {
if (i == 0) {
dot[++cnt] = s[i].r;
} else {
if (s[i].l <= dot[cnt] && s[i].r >= dot[cnt]) {
continue;
} else {
dot[++cnt] = s[i].r;
}
}
}
cout << cnt << endl;
return 0;
}


18537231688
4个月前
#include <iostream>

using namespace std;

const int N = 1e5 + 5;

int q[N];

int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> q[i];
int x;
while (m -- ) {
cin >> x;
int l = 0, r = n - 1;
while (l < r) {
int mid = l + r >> 1;
if (q[mid] >= x) r = mid;
else l = mid + 1;
}
if (q[l] != x) {
cout << "-1 -1" << endl;
} else {
cout << l << ' ';
l = 0; r = n - 1;
while (l < r) {
int mid = l + r + 1 >> 1;
if (q[mid] <= x) l = mid;
else r = mid - 1;
}
cout << l << endl;
}
}
return 0;
}


18537231688
7个月前
#include <iostream>
#include <cstdio>

using namespace std;
int a[8] = { 0 };
bool book[8] = { 0 };
int n;
void dfs(int step) {
if (step == n) {
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
printf("\n");
}
for (int i = 1; i <= n; i++) {
if (book[i] == 0) {
book[i] = 1;
a[step] = i;
dfs(step + 1);
book[i] = 0;
}
}
}

int main() {
scanf("%d", &n);

dfs(0);

return 0;
}


18537231688
7个月前
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100000;
long a[N];

long func(long a) {
int bit;
int cnt = 0;
while(a != 0) {
bit = a & 1;
cnt += ((bool)bit)?1:0;
a = a >> 1;
}
return cnt;
}

int main(void) {

int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%ld", &a[i]);
for(int i = 0; i < n; i++)  printf("%ld ", func(a[i]));
return 0;
}


18537231688
7个月前
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100000 + 10;

int a[N] = { 0 }, Tmp[N] = { 0 };

void merge_sort(int q[], int l, int r) {
if(l >= r) return;
int mid = l + r >> 1;
merge_sort(q, l , mid);
merge_sort(q, mid + 1, r);
int i = l , j = mid + 1, k = 0;
while(i <= mid && j <= r)
if(q[i] <= q[j]) Tmp[k++] = q[i++];
else Tmp[k++] = q[j++];
while(i <= mid) Tmp[k++] = q[i++];
while(j <= r) Tmp[k++] = q[j++];

for(i = l, j = 0; i <= r; i++, j++) q[i] = Tmp[j];

return ;
}

int main(void) {

int n;

scanf("%d", &n);

for (int i = 0; i < n; i++) scanf("%d", &a[i]);

merge_sort(a, 0, n - 1);

for (int i = 0; i < n; i++) printf("%d ", a[i]);

return 0;
}


18537231688
7个月前
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100000 + 10;

int a[N] = { 0 }, Tmp[N] = { 0 };

void merge_sort(int q[], int l, int r) {
if(l >= r) return;
int mid = l + r >> 1;
merge_sort(q, l , mid);
merge_sort(q, mid + 1, r);
int i = l , j = mid + 1, k = 0;
while(i <= mid && j <= r)
if(q[i] <= q[j]) Tmp[k++] = q[i++];
else Tmp[k++] = q[j++];
while(i <= mid) Tmp[k++] = q[i++];
while(j <= r) Tmp[k++] = q[j++];

for(i = l, j = 0; i <= r; i++, j++) q[i] = Tmp[j];

return ;
}

int main(void) {

int n;

scanf("%d", &n);

for (int i = 0; i < n; i++) scanf("%d", &a[i]);

merge_sort(a, 0, n - 1);

for (int i = 0; i < n; i++) printf("%d ", a[i]);

return 0;
}


18537231688
7个月前
#include <iostream>
#include <cstdio>

using namespace std;
const int N = 100000 + 10;
int q[N] = { 0 };

void Quick_Sort(int q[], int l, int r) {
if (l >= r) return;
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i++; while (q[i] < x);
do j--; while (q[j] > x);
if (i < j) swap(q[i], q[j]);
}
Quick_Sort(q, l, j);
Quick_Sort(q, j + 1, r);
}

int main(void) {
int n, k;
scanf("%d%d", &n, &k);

for (int i = 0; i < n; i++) scanf("%d", &q[i]);
Quick_Sort(q, 0, n - 1);

printf("%d", q[k - 1]);

return 0;
}


18537231688
7个月前
#include <iostream>
using namespace std;

void Q_Sort(int q[], int left, int right) {
if (left >= right) {
return;
} // 第一步
int i = left - 1, j = right + 1, x = q[left + right >> 1];
while (i < j) {
do i++; while (q[i] < x);
do j--; while (q[j] > x);
if (i < j) {
swap(q[i], q[j]);
}
}
Q_Sort(q, left, j);
Q_Sort(q, j + 1, right);
}

int main(void) {

int q[100000];
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> q[i];
Q_Sort(q, 0, n - 1);
for (int i = 0; i < n; i++) cout << q[i] << ' ';
return 0;
}


18537231688
10个月前
#include <iostream>

using namespace std;

int found(int n,int fn) {
int cnt = 0;
while (n != 0) {
if(n % 10 == fn) {
cnt ++;
}
n /= 10;
}
return cnt;
}

int main(void) {

int n , count = 0 , x;
cin >> n >> x;
for(int i = 1; i <= n; i++) {
count += found(i,x) ;
}
cout << count ;
return 0;
}