2013 ACM/ICPC Asia Regional Chengdu Online

本文解析了两道编程题目:一道涉及字符串处理的C4730题目,使用C++实现;另一道为G4734数位DP题目,通过暴力枚举解决。文章提供了完整的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

4730

各种乱搞,拼手速了。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 char str[110];
 6 int main ()
 7 {
 8     int t;
 9     scanf("%d",&t);
10     for(int Case=1; Case<=t; ++Case)
11     {
12         scanf("%s",str);
13         char *pos= strstr(str,"desu");
14         printf("Case #%d: ",Case);
15         if(pos==NULL)
16         {
17             printf("%s",str);
18         }
19         else
20         {
21             for(int i=0;i<=(pos-str-1);++i)
22             {
23                 printf("%c",str[i]);
24             }
25         }
26         printf("nanodesu\n");
27     }
28 }
View Code

4734

数位dp,见数位DP专题

J  4737

暴力,话说比赛的时候根本没想到可以暴力啊。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #define maxlen 100010
 5 using namespace std;
 6 long long n,m;
 7 long long a[maxlen];
 8 int main ()
 9 {
10     int t;
11     scanf("%d",&t);
12     for(int Case=1; Case<=t; ++Case)
13     {
14         scanf("%I64d%I64d",&n,&m);
15         for(int i=0;i<n;++i)
16             scanf("%I64d",&a[i]);
17         long long ans=0;
18         long long temp;
19         for(int i=0;i<n;++i)
20         {
21             temp=a[i];
22             for(int j=i;j<n;++j)
23             {
24                 temp|=a[j];
25                 if(temp<m)
26                     ans++;
27                 else break;
28             }
29         }
30         printf("Case #%d: %I64d\n",Case,ans);
31     }
32 }
View Code

 

转载于:https://www.cnblogs.com/shuzy/p/3456710.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值