🍎🍎🍎裁纸刀🍎🍎🍎
📋问题描述
❓思路分享
先横着切19🔪,就变成了20条,这20 条每一条都有22个二维码,那么每一条就需要21🔪,最后再加上边缘的4🔪,总数:19 + 4 + 20 * 21 = 443
🍒🍒🍒刷题统计🍒🍒🍒
📋问题描述
❓思路分享
🍒这道题本质上就是余数问题,根据题意可知,小明每周刷题5 * a + 2 * b 道题目,那么我们只需要让n对5 a + 2b取余,就知道这个n道题够他刷完整周后接下来的这周够刷几天了。
📗参考代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
long n = sc.nextLong();
long week = a * 5 + b * 2;
long t = n / week;
long c = n % week;
if(c ==0) {
System.out.println(t * 7);
return;
}
int j = 1;
while(true){
if(j<=5) c-=a;
else c-=b;
if(c<=0) break;
j++;
}
System.out.println(t*7+j);
}
}
🍐🍐🍐修剪灌木🍐🍐🍐
📋问题描述
❓思路分享
🍐拿张纸大概模拟一下,就能找出规律了:两边的最大高度是对称的并且第i 个灌木的最大高度为2 *(n-i),当n为奇数时,中间灌木的最大高度为n-1
1 | 0 | 1 | 1 |
2 | 1 | 0 | 2 |
3 | 2 | 1 | 0 |
4 | 3 | 2 | 0 |
5 | 4 | 0 | 1 |
6 | 0 | 1 | 2 |
7 | 0 | 2 | 3 |
8 | 1 | 0 | 4 |
📗参考代码
import java.util.Scanner;
public class Main {
static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] ans = new int[n + 1];
if (n%2 == 1) {
for (int i = 1; i <=(n+1)/2; i++) {
ans[i] = 2 * (n - i);
ans[n+1-i] = ans[i];
}
ans[(n+1) / 2] = n - 1;
}
if (n%2 == 0) {
for (int i = 1; i <= n/2; i++) {
ans[i] = 2 * (n - i);
ans[n+1-i] = ans[i];
}
}
for (int i = 1; i <= n; i++) {
System.out.println(ans[i]);
}
}
}
🌈🌈🌈k倍区间🌈🌈🌈
📋问题描述
❓思路分享
🌈这道题考察同余数定理 ,即如果a%k = b%k,那么有(a-b)%k==0.
📗参考代码
package 三十天打卡.第十天;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class k倍区间 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
//注意开long数组,数据量较大
long[] s = new long[N + 1];
//Map前面也得用long,因为有long参与的运算返回值也是long
Map<Long,Integer> map = new HashMap<Long,Integer>();
//获得前缀和数组
for (int i = 1; i <=N ; ++i) {
s[i] = sc.nextInt();
s[i] += s[i-1];
}
long ans = 0;
//千万不能忘记将这个放入
map.put(0L,1);
for (int i = 1; i <=N ; ++i) {
ans += map.getOrDefault(s[i]%K,0);
map.put(s[i]%K,map.getOrDefault(s[i]%K,0) + 1);
}
System.out.println(ans);
}
}