给出一个01串
然后给出两种操作,任意交换两个数字位置和合并1
求通过操作后最短的字符串
直接计算多少个1就行了,,,
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
#include<iomanip>
#include<functional>
using namespace std;
const int maxn = 5*int(1e5)+100;
const int BN = 30;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-6;
typedef long long LL;
typedef unsigned long long ull;
char s[1000];
int main() {
int n;
while (~scanf("%d%s", &n, &s)) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
cnt++;
}
}
if (cnt != 0) printf("1");
for (int i = 0; i < n - cnt; i++)
printf("0");
printf("\n");
}
return 0;
}
B. Lara Croft and the New Game
一个人走迷宫,他先从左上角直走到右下角,然后再剩下的地方走蛇形,
问第k步时他在那里
扫描二维码关注公众号,回复:
2509607 查看本文章
手动模拟一下 ifelse大法
注意一下k会炸int,用longlong吧
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
#include<iomanip>
#include<functional>
using namespace std;
const int maxn = 5*int(1e5)+100;
const int BN = 30;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-6;
typedef long long LL;
typedef unsigned long long ull;
int main() {
LL a, b, k;
while (~scanf("%I64d%I64d%I64d", &a, &b, &k)) {
if (k < a)
printf("%I64d 1\n", k + 1);
else {
k = k - a + 1;
LL t1 = k / (b - 1), t2 = k % (b - 1);
if (t2 == 0) t1--;
LL x = a - t1, y;
if (t1 & 1) {
if (t2 == 0) y = 2;
else y = b - t2 + 1;
}
else {
if (t2 == 0) y = b;
else y = t2 + 1;
}
printf("%I64d %I64d\n", x, y);
}
}
return 0;
}
给出多个区间,问是否存在一个区间完全覆盖另一个区间,如果有输出这两个区间是第几个
排序,优先L升序 R降序贪心
因为只要一个所以直接扫到存在就输出
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
#include<iomanip>
#include<functional>
using namespace std;
const int maxn = 4*int(1e5)+100;
const int BN = 30;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-6;
typedef long long LL;
typedef unsigned long long ull;
struct nodes {
int l, r, id;
bool operator<(const nodes &a)const {
if (l == a.l) return r>a.r;
return l < a.l;
}
}seg[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &seg[i].l, &seg[i].r);
seg[i].id = i + 1;
}
sort(seg, seg + n);
bool flag = false;
for (int i = 1; i < n; i++) {
if (seg[i].r <= seg[i - 1].r) {
flag = true;
printf("%d %d\n", seg[i].id, seg[i - 1].id);
break;
}
}
if (!flag) printf("-1 -1\n");
return 0;
}