T1: 题意:一张长为a,宽为b地毯,能否被边长为c的地毯覆盖。 分数:70 正确代码:
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
int main(){
ll a,b,c;
cin>>a>>b>>c;
if(a%c==0&&b%c==0){//判断a能否c整除,判断b能否c整除
cout<<(a/c)*(b/c);
}else{
cout<<-1;
}
return 0;
}我用a×b在除c×c,使结果报掉了 T3: 题意:总共有n棵柳树,每一棵间隔都为x。 现在他需要对这些树做一些操作,使得在「这n棵树的起点不变」的同时,任意两棵树的间隔都为y。 分数:0 正确代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main() {
ll n, x, y;
cin >> n >> x >> y;
//枚举x的倍数能否被y整除
ll cnt = 0;
for (ll i = 0; i < n; i++) { //从0倍到n-1倍
if (x * i % y == 0) {
cnt++;
}
}
cout << cnt;
return 0;
}做题时,没有理清楚逻辑 T4: 题意:5个人每人跑10次,求最少跑多少米 正确代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
ll a[15], b[15], c[15], d[15], e[15];
int main() {
for (int i = 1; i <= 10; i++) { //记录第一个人1公里到10公里需要的时间
cin >> a[i];
}
for (int i = 1; i <= 10; i++) { //记录第二个人1公里到10公里需要的时间
cin >> b[i];
}
for (int i = 1; i <= 10; i++) { //记录第三个人1公里到10公里需要的时间
cin >> c[i];
}
for (int i = 1; i <= 10; i++) { //记录第四个人1公里到10公里需要的时间
cin >> d[i];
}
for (int i = 1; i <= 10; i++) { //记录第五个人1公里到10公里需要的时间
cin >> e[i];
}
//找刚好跑了25公里,并且时间最短的方案
ll minn = INT_MAX, ans1, ans2, ans3, ans4, ans5;
for (int i1 = 1; i1 <= 10; i1++) { //枚举第一个人跑步的距离
for (int i2 = 1; i2 <= 10; i2++) { //枚举第二个人跑步的距离
for (int i3 = 1; i3 <= 10; i3++) { //枚举第三个人跑步的距离
for (int i4 = 1; i4 <= 10; i4++) { //枚举第四个人跑步的距离
for (int i5 = 1; i5 <= 10; i5++) { //枚举第五个人跑步的距离
if (i1 + i2 + i3 + i4 + i5 == 25 && a[i1] + b[i2] + c[i3] + d[i4] + e[i5] < minn) {
minn = a[i1] + b[i2] + c[i3] + d[i4] + e[i5];
ans1 = i1;
ans2 = i2;
ans3 = i3;
ans4 = i4;
ans5 = i5;
}
}
}
}
}
}
cout << minn << endl << ans1 << " " << ans2 << " " << ans3 << " " << ans4 << " " << ans5;
return 0;
}有思路编写速度较慢,没有写完。 T5: 题意:贝西从谷仓出发,位置为 0,初始贝西没有钱。贝西收回她的所有借债,并且还清她的欠债所需行走的最短距离是多少? 正确代码:
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main() {
//记录当前的钱的数量dq
//记录已经走了多少步ans
//记录在欠钱的时候往前走了多少步cnt
ll n, dq = 0, ans = 0, cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
ll x;
cin >> x; //拿到账单
dq += x; //记录当前的钱的数量
ans++;//走了一步
if (dq < 0) { //欠钱
cnt++;//记录欠钱步数
} else {
ans += cnt * 2; //还钱一个来回
cnt = 0; //欠钱步数归0
}
}
cout << ans;
return 0;
}模拟整体细节梳理有问题,没找到关键变量点及整体流程的梳理存在问题