T1 : Test
↓ std
# include <bits/stdc++.h>
using namespace std;
int n, k, sum;
int p[1000010];
int main () {
scanf ("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf ("%d", &p[i]);
if (i % k == 0)
sum += p[i];
}
printf ("%d %d\n", n / k, sum);
return 0;
}
T2 : Array
↓ std
# include <bits/stdc++.h>
using namespace std;
long long T, n, k;
long long a[100010];
int main () {
scanf ("%lld", &T);
while (T--) {
long long sum = 0, maxn = 0;
bool flag = false;
scanf ("%lld%lld", &n, &k);
for (long long i = 1; i <= n; i++) {
scanf ("%d", &a[i]);
if (a[i] % k != 0)
flag = true;
a[i] /= k, sum += a[i], maxn = max (a[i], maxn);
}
if (flag == true || sum < maxn * 2 || sum % 2 != 0)
printf ("No\n");
else printf ("Yes\n");
}
return 0;
}
T3 : Num
↓ std
# include <bits/stdc++.h>
using namespace std;
char ch;
int flag;
int sum, tmp, ans;
int main () {
ch = getchar();
while (ch < '0' || ch > '1') ch = getchar();
while (ch >= '0' && ch <= '1') {
sum++;
if (ch == '0') tmp++;
else {
ans += tmp;
tmp = 0;
}
ch = getchar();
if (ch == '1') flag = 1;
}
if (flag)
printf ("%d\n", sum + ans + 1);
else printf ("%d\n", sum - 1);
return 0;
}
T4 : Segment
↓ std
# include <bits/stdc++.h>
using namespace std;
struct stu {
int w,v;
} a[2500000];
inline bool cmp (stu x, stu y) {
return x.w < y.w;
}
int n, cnt;
int sum, tmp = 1;
int main () {
scanf ("%d", &n);
for (int i = 1; i <= n; i++){
int l, r;
scanf ("%d%d", &l, &r);
a[++cnt].w = l, a[cnt].v = 1, a[++cnt].w = r + 1, a[cnt].v = -1;
}
sort (a + 1, a + cnt + 1, cmp);
for (int i = 1; i <= cnt; i++) {
while (tmp <= i)
sum += a[tmp++].v;
if (sum == n) {
printf ("%d", a[i].w);
return 0;
}
}
printf ("Impossible\n");
return 0;
}
网友评论