只做了四道水题
A
ans = (m/n)ans + avg
注意m == n 和 avg == 0.0的情况
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
int a[222];
int main()
{
int n, m;
while (scanf("%d", &n) != EOF)
{
int i, j , k, sum = 0;
double ans;
for (i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
sum += a[i];
}
scanf("%d", &m);
for (i = 0; i < m; ++i)
scanf("%d", &k);
if (sum == 0)
{
printf("0.00\n");
}
else if (n == m)
{
printf("inf\n");
}
else
{
ans = sum;
ans = ans / (n - m);
printf("%.2lf\n", ans);
}
}
return 0;
}
C 统计进位,只要预处理1-100000000的前缀和中每个位有多少个一,然后每次询问b-(a-1)再统计即可
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
void solve(LL cnt[], LL num)
{
LL i, j, k, bas = 1, lim = 0;
for (i = 0; i <= 64; ++i)
{
if (num <= lim) break;
cnt[i] = (num - lim) / (bas * 2) * bas;
if ((num - lim) % (bas * 2) >= bas) cnt[i] = cnt[i] + bas;
else cnt[i] = cnt[i] + ((num-lim) %(bas * 2));
bas *= 2; lim = bas - 1;
}
}
LL c1[100], c2[100];
int main()
{
LL a, b;
while (scanf("%I64d%I64d", &a, &b) != EOF)
{
memset(c1, 0, sizeof(c1));memset(c2, 0, sizeof(c2));
solve(c1, a - 1); solve(c2, b);
LL tot = 0, ans = 0;
// for (int i = 0; i <= 10; ++i)
// printf("%d ", c1[i]);
// printf("\n");
// for (int i = 0; i <= 10; ++i)
// printf("%d ", c2[i]);
// printf("\n");
for (int i = 0; i <= 64; ++i)
c2[i] = c2[i] - c1[i];
for (int i = 0; i <= 64; ++i)
{
ans = ans + c2[i] / 2;
c2[i + 1] += c2[i] / 2;
}
printf("%I64d\n", ans);
}
return 0;
}
H 统计哪个数字重复
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
int a[1111];
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
int i, x, t;
memset(a, 0, sizeof(a));
for (i = 0; i <= n; ++i)
{
scanf("%d", &x);
if (a[x]) t = x;
a[x]++;
}
printf("%d\n", t);
}
return 0;
}
K
枚举两个区间的X的gcd的倍数在不在 两个区间只差的区间内,【Z[j]-Y[i],Y[j] - Z[i]】
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
int X[1111], Y[1111], Z[1111];
inline int gcd(int a, int b)
{
if (!b) return a;
return gcd(b, a % b);
}
bool check(int i, int j)
{
if (Z[i] < Y[j] || Y[i] > Z[j])
{
int k;
int d = gcd(X[i], X[j]);
if (Z[i] > Z[j]) {k = i; i = j; j = k;}
int l, r;
l = Y[j] - Z[i]; r = Z[j] - Y[i];
// printf("%d %d %d\n", d, l, r);
if (l % d == 0 || r % d == 0)
return true;
else
return l / d != r / d;
}
return true;
}
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
int i, j, k;
for (i = 0; i < n; ++i)
scanf("%d%d%d", &X[i], &Y[i], &Z[i]);
bool flag = true;
for (i = 0; i < n; ++i)
for (j = i + 1; j < n; ++j)
{
if (check(i, j))
{
flag = false;
break;
}
}
if (flag) printf("Can Take off\n");
else printf("Cannot Take off\n");
}
return 0;
}