2019河北省大学生程序设计竞赛(重现赛)

G 点我

X腿与队友到河北省来参加2019河北省大学生程序设计竞赛,然而这场比赛的题目难度实在是太高了。比赛开始一个小时后,X腿仍然没有做出一个题。这时候,X腿惊讶的发现电脑屏幕上出现了一个神奇按钮,按钮上写着”点我签到“。X腿非常兴奋,于是他点击了这个按钮,只见屏幕上的题目状态由“未提交”转变成了“答案错误”。他又点击了一下这个按钮,题目状态由“答案错误”变成了“通过”!

当题目状态为“通过”时,我们认为X腿签到成功了。

通过多次实验,X腿总结出以下经验:

当题目状态为”未提交“时,点击按钮后题目状态将变为”答案错误“。

当题目状态为”答案错误“时,点击按钮后题目状态将变为”通过“。

当题目状态为”*通过“时,点击按钮后题目状态将变为”答案错误“。

现在,已知初始的题目状态为”未提交“。由于X腿过于兴奋,点击了 n 次按钮。请问X腿签到成功了吗?

输入描述:

一行一个正整数 n,代表X腿点击了 n 次按钮。
0n1000000≤n≤100000

输出描述:

输出一行。如果X腿签到成功,请你输出“qiandaochenggong”;否则输出"qiandaoshibai”。(输出均不含引号)
示例1

输入

复制
3

输出

复制
qiandaoshibai

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 //#include <>
15 using namespace std;
16  
17 int main()
18 {
19     long long n;
20     scanf("%lld",&n);
21      
22     if(n==0)
23     {
24         cout<<"qiandaoshibai"<<endl;
25     }
26      
27     else if(n%2!=0)
28     {
29         cout<<"qiandaoshibai"<<endl;
30     }
31      
32     else if(n%2==0)
33     {
34         cout<<"qiandaochenggong"<<endl;
35     }
36     return 0;
37 }
G

。链接:https://ac.nowcoder.com/acm/contest/903/H
来源:牛客网
H 天神的密码

2018年,icebound打开了神殿。而在2019年,icebound正在试图破解天神的密码,以期获得天神的力量。

icebound发现,想要得到神的密码,必须先要完成一个祭祀仪式。在这个祭祀仪式上,我们首先会追随神的指引,得到两个正整数 N和 K。随后,我们令 X=NKX=NK,得到天神喜欢的数字X。

利用 X,我们进行以下方式得到天神最后的密码:

步骤 1 将 X每个数位上的数字相加得到 Y。

步骤 2 令 X=Y

步骤 3 反复执行 步骤 1,直到 X只有一个数位时停止,即 1X91≤X≤9。此时的 X 即为天神的密码。

比如:当 N=11,K=2 时,首先我们得到 X=NK=112=121X=NK=112=121。然后我们把 X 的各个数位上的数相加,即 Y=1+2+1=4。此时 X=Y=4,X 仅有一个数位了,所以我们停止操作,得到天神的密码为4。

icebound许诺,如果他获得了天神的力量,一定保你荣华富贵,全家幸福,还会另外送你一块金牌。所以,请你帮助他计算天神的密码。

输入描述:

首先第一行一个整数 T ,代表数据组数。
随后 T 行,每行两个数 N,K ,用空格隔开。
1T201≤T≤20,1N1091≤N≤109,1K21≤K≤2

输出描述:

一行一个整数 X,表示天神的密码。
示例1

输入

复制
2
11 2
100 1

输出

复制
4
1

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 //#include <>
15 using namespace std;
16  
17 long long ksm(long long n,int k)//求天神喜欢的数字
18 {
19     long long x=1;
20     long long cnt=n;
21     while(k)
22     {
23         if(k&1)
24         {
25             x*=cnt;
26         }
27         cnt*=cnt;
28         k>>=1;
29     }
30     return x;
31 }
32  
33 long long bitadd(long long x)//数位相加
34 {
35     long long codes=0;
36     int box;
37     if(x>=1&&x<=9)
38         return x;
39     while(x>9)
40    {
41         codes=0;
42         while(x>0)
43         {
44             box=x%10;
45             codes=box+codes;
46             x=x/10;
47         }
48         x=codes;
49     }
50      
51  
52     return codes;
53 }
54 int main()
55 {
56     int t;
57     long long n;
58     int k;
59     long long x,answer;
60     //输入组数
61     scanf("%d",&t);
62      
63     while(t--)
64     {
65         scanf("%lld%d",&n,&k);
66         x=ksm(n,k);
67         answer=bitadd(x);
68         printf("%lld
",answer);
69     }
70      
71     //
72      
73     return 0;
74 }
H

K 河北美食

icebound最喜欢吃河北菜,于是他想要大厨做一桌河北菜宴请宾客。icebound购买了一些食材,并且制订了宴会的菜单。但是他并不知道这些食材是否足够,所以希望你写一个程序帮助他。
icebound将会给出每种食材的名称和数量,以及完整的菜单。菜单将包含每种菜品所需的食材及数量。菜单上的每道菜只需制作一次。

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 //#include <>
15 using namespace std;
16 //食材结构体
17 struct ingre{
18     string food;
19     long num;
20 }in[1009];
21  
22  
23 int main()
24     //每道菜只制作一次
25      
26 {
27     int n,m;//食材的种类 菜品数量
28     int k;//k<=n,代表这种菜品所需的食材种数
29     int ks[15];
30     int flag=0,i;
31      
32     scanf("%d%d",&n,&m);
33     for(int j=0;j<n;++j)
34     {
35         cin>>in[j].food;
36         scanf("%d",&in[j].num);
37     }
38      
39     while(m--)//制作菜品中~~~~~
40     {
41         int types;
42         scanf("%d",&types);
43          
44         while(types--)
45         {
46             string foodie;
47             int numbers;
48             cin>>foodie;
49     //        cout<<"-=====foodie is "<<foodie<<endl;
50             scanf("%d",&numbers);
51         //  cout<<"-=====numbers is "<<numbers<<endl;
52              
53             for(i=0;i<n;++i)
54             {
55                 if(in[i].food==foodie)
56                 {
57 //                cout<< in[i].food;  printf("找到要用的食材了%d
",in[i].num);//测试用!
58                     in[i].num=in[i].num-numbers;
59  /*                cout<< in[i].food; printf("现在是%d
",in[i].num);//测试用!
60                     cout<<"~~~~foodie is "<<foodie<<endl;
61                     cout<<"~~~~numbers is "<<numbers<<endl;*/
62                     break;
63                 }
64             }
65             if(in[i].num<0)
66             {
67                 flag=1;
68   //              printf("因为数量不足所以跳出orz1
");
69      //            cout<<"现在变为"<<in[i].food<<" "<<in[i].num<<endl;
70                 break;
71             }
72         }
73         if(flag)
74         {
75 //          printf("因为数量不足所以跳出orz2
");
76 //         cout<<"现在变为"<<in[i].food<<" "<<in[i].num<<endl;
77            break;
78         }
79     }
80      
81     if(flag)
82         {
83            printf("NO
");
84 //           printf("因为数量不足所以跳出orz2
");
85 //            cout<<"现在变为"<<in[i].food<<" "<<in[i].num<<endl;
86         }
87     else{
88         printf("YES
");
89         for(i=0;i<n;++i)
90         {
91             //如果某种食材全部被用完,则不输出该食材。
92             if(in[i].num==0)
93                 continue;
94              cout<<in[i].food<<" "<<in[i].num<<endl;
95         }
96     }
97     return 0;
98 }
K
 
原文地址:https://www.cnblogs.com/greenaway07/p/10941233.html