乘积尾数
找2,5个数取最小值
#include <iostream>
#include <cmath>
using namespace std;
int num1, num2, m;
void sum(int x)
{
while (1)
{
if (x % 2 != 0 && x % 5 != 0)
{
return;
}
if (x % 2 == 0)
{
x /= 2;
num1++;
}
if (x % 5 == 0)
{
x /= 5;
num2++;
}
}
}
int main() {
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
cin >> m;
sum(m);
}
}
cout << min(num1, num2) << endl;
return 0;
}
全球变暖
dfs搜索
#include <iostream>
#include <cstdio>
using namespace std;
int mp[110][110];
int ans[11000];
bool vis[110][110];
void dfs(int x, int y, int k)
{
if (mp[x][y] == '.')
return;
if (vis[x][y])
return;
vis[x][y] = 1;
if (mp[x - 1][y] == '#' && mp[x + 1][y] == '#' && mp[x][y - 1] == '#' && mp[x][y + 1] == '#')
ans[k]++;
dfs(x + 1, y, k);
dfs(x - 1, y, k);
dfs(x, y - 1, k);
dfs(x, y + 1, k);
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cin >> mp[i][j];
}
int len = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (mp[i][j] == '#' && !vis[i][j])
{
dfs(i, j, len);
len++;
}
}
}
int sum = 0;
for (int i = 0; i < len; i++)
{
if (ans[i] == 0) sum++;
}
cout << sum;
return 0;
}
明码
十进制转二进制
#include <iostream>
using namespace std;
void ej(int n)
{
int k = 1, s[9];
while (k)
{
for (k = 1; k < 9; k++)
{
s[k] = n % 2;
n = n / 2;
}
for (k = 8; k > 0; k--)
{
if (s[k] == 0)printf(" ");
else printf(".");
}
}
}
void fej(int n)
{
int k = 1, s[9];
n = -n;
while (k)
{
for (k = 1; k < 9; k++)
{
if (n % 2 == 0)
s[k] = 1;
else
s[k] = 0;
n = n / 2;
}
if (s[1] == 0)
{
s[1] = 1;
for (k = 8; k > 0; k--)
if (s[k] == 0)printf(" ");
else printf(".");
}
else
{
s[1] += 1;
for (k = 1; k < 9; k++)
{
if (s[k] == 1)
{
break;
}
else if (s[k] == 2)
{
s[k] = 0;
s[k + 1] += 1;
}
}
for (k = 8; k > 0; k--)
if (s[k] == 0)printf(" ");
else printf(".");
}
}
}
int main()
{
int n, i, j;
for (j = 0; j < 10; j++)
{
for (i = 1; i < 33; i++)
{
cin >> n;
if (n >= 0)
ej(n);
else
fej(n);
if (i % 2 == 0)
printf("\n");
}
}
int ans = 1;
for (int i = 1; i <= 9; i++)
{
ans *= 9;
}
cout << ans;
return 0;
}
测试次数
dp就表示有i部手机j层楼的情况下 最坏运气下需要测试的次数
#include <iostream>
using namespace std;
int dp[5][1007];
int main()
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 1000; j++) dp[i][j] = j;
}
for (int i = 1; i <= 1000; i++)
{
for (int j = 2; j <= 3; j++)
{
for (int k = 1; k < i; k++) dp[j][i] = min(dp[j][i], max(dp[j - 1][k - 1], dp[j][i - k]) + 1);
}
}
cout << dp[3][1000] << endl;
return 0;
}
递增三元组
#include <iostream>
using namespace std;
int main()
{
int n, a[4][100005] = { 0 };
int j, i, k, sum = 0;
cin >> n;
for (j = 0; j < 3; j++)
{
for (i = 0; i < n; i++)
{
cin >> a[j][i];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (a[1][j] < a[2][i])
{
for (k = 0; k < n; k++)
{
if (a[0][k] >= a[1][j]) break;
}
sum += k;
}
}
}
cout << sum;
return 0;
}
螺旋折线
#include <iostream>
using namespace std;
int main()
{
int a, b, x1 = 0, y1 = 0, x2 = 0, y2 = 0, s = 0;
cin >> a >> b;
while (1)
{
cout << x1 << y1 << endl;
x1 = y1 - 1;
if (y1 == b && (a >= x1 && a <= x2))
{
s += (x2 - a);
break;
}
s += (x2 - x1);
x2 = x1;
cout << x1 << y1 << endl;
y1 = -x1;
if (x1 == a && (b >= y2 && b <= y1))
{
s += (b - y2);
break;
}
s += (y1 - y2);
y2 = y1;
cout << x1 << y1 << endl;
x1 = y1;
if (y1 == b && (a >= x2 && a <= x1))
{
s += (a - x2);
break;
}
s += (x1 - x2);
x2 = x1;
cout << x1 << y1 << endl;
y1 = -x1;
if (x1 == a && (b >= y1 && b <= y2))
{
s += (y2 - b);
break;
}
s += (y2 - y1);
y2 = y1;
}
cout << s << endl;
return 0;
}
日志统计
#include <iostream>
using namespace std;
void sort(int a[][10], int n)
{
int i, j;
for (j = n - 1; j > 0; j--)
for (i = 0; i < j; i++)
{
if (a[i][1] > a[i + 1][1])
{
a[i][1] ^= a[i + 1][1];
a[i + 1][1] ^= a[i][1];
a[i][1] ^= a[i + 1][1];
a[i][0] ^= a[i + 1][0];
a[i + 1][0] ^= a[i][0];
a[i][0] ^= a[i + 1][0];
}
}
}
int main()
{
int n, d, k;
int a[10][10] = { 0 }, b[20] = { 0 };
int i, j = 0;
cin >> n >> d >> k;
for (i = 0; i < n; i++)
{
cin >> a[i][0] >> a[i][1];
}
sort(a, n);
for (i = 0; i < n - 1; i++)
{
if (a[i][1] == a[i + 1][1])
{
if (abs(a[i][0] - a[i + 1][0]) < k)
cout << a[i][1] << endl;
}
}
return 0;
}
日志统计
当点赞数 >= k时,则判定其为热帖.加入结果集最终输出即可
#include<iostream>
#include<algorithm>
using namespace std;
#define x first
#define y second
const int N = 1e5 + 10;
typedef pair<int, int> PII;
PII q[N];
int cnt[N];
bool st[N];
int n, d, k;
int main()
{
cin >> n >> d >> k;
for (int i = 0; i < n; i++)
cin >> q[i].x >> q[i].y;
sort(q, q + n);
for (int i = 0, j = 0; i < n; i++)
{
cnt[q[i].y] ++;
while (q[i].x - q[j].x >= d)
{
cnt[q[j].y] --;
j++;
}
if (cnt[q[i].y] >= k)
st[q[i].y] = true;
}
for (int i = 0; i <= 100000; i++)
if (st[i])
cout << i << endl;
return 0;
}