首页 > 其他 > 详细

第七周周赛A、B、H

时间:2019-12-09 12:00:55      阅读:71      评论:0      收藏:0      [点我收藏+]

B题0和1:

https://www.cnblogs.com/kongbursi-2292702937/p/11268230.html

 

A题:

 题目数据非常小,所以这道题是不卡时间的。就直接dfs递归就完了

可能有人会问怎么dfs,那就枚举每一个宠物的技能。如果概率大于题目要求的k的话就统计一下最小代价就完了

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<iostream>
 5 using namespace std;
 6 const int maxn=55;
 7 const int INF=0x3f3f3f3f;
 8 int v[maxn],k,n,w[maxn],p[maxn],minn=INF;
 9 void dfs(int x,int y)
10 {
11     if(x>=k)
12     {
13         minn=min(minn,y);
14         return;
15     }
16     for(int i=1; i<=n; ++i)
17     {
18         if(v[i])
19         {
20             v[i]--;
21             dfs(x+w[i],y+p[i]);
22             v[i]++;
23         }
24     }
25 }
26 int main()
27 {
28     scanf("%d%d",&n,&k);
29     for(int i=1; i<=n; ++i)
30     {
31         scanf("%d",&v[i]);
32     }
33     for(int i=1; i<=n; ++i)
34     {
35         scanf("%d",&w[i]);
36     }
37     for(int i=1; i<=n; ++i)
38     {
39         scanf("%d",&p[i]);
40     }
41     dfs(0,0);
42     if(minn==INF)
43         printf("NO\n");
44     else printf("%d\n",minn);
45     return 0;
46 }

 

H题:

题目描述的字典树部分可以不看(给你说可以用字典树来做,又没说必须用它来做)

看一下数据又不大,那就暴力写呗

直接看代码吧

 

代码:

 1 //#include <iostream>
 2 //#include <cstdio>
 3 //#include <cstring>
 4 //#include <cstdlib>
 5 //#include <algorithm>
 6 //using namespace std;
 7 //typedef long long ll;
 8 //const int maxn=26;
 9 //const int mod=998244353;
10 //typedef struct Trie* TrieNode;
11 #include <cstdio>
12 #include <string.h>
13 int main()
14 {
15     char num[10005][15];
16     int num_1[10000] = {0};
17     int max = 0;
18     int count;
19     int count_1;
20     scanf("%d",&count);
21     for (int i = 0; i < count; i++)
22     {
23         scanf("%s",num[i]);
24         for(int j = 0; j <= i; j++)
25         {
26             if(strcmp(num[i], num[j])==0)
27             {
28                 num_1[i]++;
29             }
30         }
31     }
32     for (int i =0; i < count; i++)
33     {
34         if( max < num_1[i])
35         {
36             max = num_1[i];
37             count_1 = i;
38         }
39     }
40 //    FILE *fp=NULL;
41 //    fp=fopen("4.txt","w");
42     printf("%s %d",num[count_1],max);
43     //fclose(fp);
44     return 0;
45 }

 

 

第七周周赛A、B、H

原文:https://www.cnblogs.com/kongbursi-2292702937/p/12009470.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!