考试题解(5/10):
#include
using namespace std;
typedef long long ll;
ll a, b, n;
int main()
{
cin >> a >> b >> n;
int num[7] = { a,a,a,a,a,b,b };
ll sum=0;
ll ans = 0;
while(1)
for (ll i = 0; i < 7; i++)
{
sum += num[i];
ans++;
if (sum >= n) {
cout << ans;
return 0;
}
}
}
考试时敲太快,在定义周数组时把ll敲成了int,导致无法存储大数字从而出错。小看了第一题,无脑循环遍历,导致超时。
纠正题解(先计算出一周题量,大大减少循环次数 AC):
#include
using namespace std;
typedef long long ll;
ll a, b, n;
int main()
{
cin >> a >> b >> n;
ll week = a*5+b+b;//一周题量
ll num[7] = { a,a,a,a,a,b,b };
ll sum=0;
ll ans = 0;
ll weekNum = n/week;
ll last = n%week;
if(last == 0)
cout<= last)
{
cout << ans + weekNum*7;
return 0;
}
}
}
return 0;
}
试题D: 修剪灌木
考试题解(9/10):
#include
using namespace std;
typedef long long ll;
int a[10000];
ll maxs[10000];
ll n;
int main()
{
cin >> n;
int d=0;//移动
ll k = -1;//左-1 右1
int h = 10000;
while (h--)
{
for (int i = 0; i < n; i++)//生长
a[i]++;
for (int i = 0; i < n; i++)
if (a[i] > maxs[i])
maxs[i] = a[i];
if (d == 0 || d == n - 1)
k = k * (-1);
a[d] = 0;
if (k == 1) d++;
else d--;
}
for (int i = 0; i < n; i++)
cout << maxs[i] << endl;
}
自己太菜了,只会遍历得不到满分。但得到了9/10分数已经可以了。
大佬题解(只要找到一棵树距离最左边或最右边的树哪边长,再乘以2即最长高度):
#include
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cout<
试题E: X进制减法
试题F: 统计子矩阵
考试题解(1/10):
#include
using namespace std;
typedef long long ll;
ll n, m, k;
int a[505][505];
//最大点坐标(m,n)
int main()
{
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
ll sum = 0;
int ans = 0;
for (int x = 0; x < m; x++)
for (int y = 0; y < n; y++)
{
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++)
{
if (x + i <= n && y + j <= n)
{
for (int x_ = x; x_ <= x + i; x_++)
for (int y_ = y; y_ <= y + j; y_++)
sum += a[x_][y_];
if (sum>0&&sum <= k)
{
ans++;
}
}
sum = 0;
}
}
cout << ans;
return 0;
}
矩阵的输入就写错了,后面逻辑也有问题。不够冷静。
纠正题解(纠正了矩阵的输入,逻辑,但算法能力有限只能过4/10,待优化):
#include
using namespace std;
typedef long long ll;
ll n, m, k;
int a[505][505];
//最大点坐标(m,n)
int main()
{
cin >> n >> m >> k;
//矩阵的输入方式,易错
for (int y = 1; y <= n; y++)
for (int x = 1; x <= m; x++)
cin >> a[x][y];
ll sum = 0;
int ans = 0;
//遍历每个点
for (int x0 = 1; x0 <= m; x0++)
for (int y0 = 1; y0 <= n; y0++)
{
//遍历该点右下方每个点
for(int x1 = x0;x1<=m;x1++)
for(int y1 = y0;y1<=n;y1++)
{
//如果两点相同
if(x0==x1 && y0==y1)
{
if(a[x0][y0]<=k)
{
ans++;
}
}
else
{
sum=0;
//计算两点所确定的矩阵数字和
for(int x_=x0;x_<=x1;x_++)
for(int y_=y0;y_<=y1;y_++)
{
sum+=a[x_][y_];
}
if(sum<=k)
{
ans++;
}
}
}
}
cout << ans;
return 0;
}
试题G: 积木画
试题H:扫雷
考试题解(3/10):
#include
#include
using namespace std;
typedef long long ll;
struct L {
float x, y, r;
};
L zha[50000];
L jian[50000];
int n, m;//n个炸雷 m个火箭
int vis[50000];//标记炸雷是否爆炸
int getd(L a, L b) {//获取两点之间距离
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void pop(L baozha) {//递归爆破
for (int i = 0; i < n; i++)
{
if (getd(zha[i], baozha) <= baozha.r&&vis[i]==0)
{
vis[i] = 1;
pop(zha[i]);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> zha[i].x >> zha[i].y >> zha[i].r;
for (int i = 0; i < m; i++)
cin >> jian[i].x >> jian[i].y >> jian[i].r;
for (int i = 0; i < m; i++) {
pop(jian[i]);
}
int ans = 0;
for (int i = 0; i < n; i++)
if (vis[i] == 1)
ans++;
cout << ans;
return 0;
}
刚看到题目感觉不是我可以做的题,但看完题感觉也没有那么难于是花时间做了,通过了3/10。考试时忘记两点之间距离应该是float类型,修改后可以通过4/10。
试题I: 李白打酒加强版
试题J:砍竹子