cf round441

cf round441

A

题目要求

有三座房子 给出两两之间的距离
从固定点出发 算上起点要到达n个位置 每次都会去离他最近的房子
问最后总的最小移动距离是多少

参考AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
int main(){
// freopen("input.txt","r",stdin);
scanf("%d",&n);
scanf("%d%d%d",&a,&b,&c);
int ans=0,pos=1;
n--;
while(n--){
if(pos==1){
if(a>=b) ans+=b,pos=2;
else ans+=a,pos=3;
}
else if(pos==2){
if(b>=c) ans+=c,pos=3;
else ans+=b,pos=1;
}
else if(pos==3){
if(a>=c) ans+=c,pos=2;
else ans+=a,pos=1;
}
}
printf("%d\n",ans);
return 0;
}

思路

模拟

B

题目要求

给出n个数字 问是否可以从中挑选k个数字 使得任意2个数字的差都可以被m整除

参考AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
#define maxn 100050
using namespace std;
int n,k,m;
int a[maxn],hashh[maxn];
int main(){
// freopen("input.txt","r",stdin);
scanf("%d%d%d",&n,&k,&m);
memset(hashh,0,sizeof(hashh));
int ans=-1;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int temp=a[i]%m;
hashh[temp]++;
if(hashh[temp]>=k) ans=temp;
}
if(ans==-1){
puts("No");
return 0;
}
int num=1;
puts("Yes");
for(int i=1;i<=n && num<=k;i++){
if(a[i]%m==ans){
printf("%d ",a[i]);
num++;
}
}
puts("");
return 0;
}

思路

记录每个数字mod m以后的数字出现次数 如果出现次数大于等于k 那么存在 否则不存在
接着输出这k个mod m==ans的数字即可
如果2个数字mod m的大小相等 相减后就可以被m整除

C

题目要求

定义函数:f(x)=x+十进制下x各位上的数字之和
输出所有可能的x值

参考AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;
int re[100000],len;
int main(){
int n;
scanf("%d",&n);
len=0;
for(int i=max(1,n-100);i<=n;i++){
int x=i,ans=0;
while(x){
ans+=x%10;
x/=10;
}
if(ans+i==n) re[++len]=i;
}
printf("%d\n",len);
for(int i=1;i<=len;i++) printf("%d\n",re[i]);
return 0;
}

思路

部分枚举 只要枚举n-100到n即可
所有dit之和不超过100

文章目录
  1. 1. cf round441
    1. 1.1. A
      1. 1.1.1. 题目要求
      2. 1.1.2. 参考AC代码
      3. 1.1.3. 思路
    2. 1.2. B
      1. 1.2.1. 题目要求
      2. 1.2.2. 参考AC代码
      3. 1.2.3. 思路
    3. 1.3. C
      1. 1.3.1. 题目要求
      2. 1.3.2. 参考AC代码
      3. 1.3.3. 思路
|