BestCoder Round #13(前两题)

这一次又只出了一题,第二题没有分析好,竟然直接copy代码,不过长见识了。。

第一题给了一些限制条件,自己没有分析好,就去乱搞,结果各种不对,后来有读题才发现。。暴力乱搞。。

题目:

Beautiful Palindrome Number


Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 657    Accepted Submission(s): 369


Problem Description
  
  
A positive integer x can represent as (a1a2akaka2a1)10 or (a1a2ak1akak1a2a1)10 of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies 0<a1<a2<<ak9 , we call x is a Beautiful Palindrome Number.
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10N .
 
Input
  
  
The first line in the input file is an integer T(1T7) , indicating the number of test cases.
Then T lines follow, each line represent an integer N(0N6) .
 
Output
  
  
For each test case, output the number of Beautiful Palindrome Number.
 
Sample Input
  
  
2 1 6
 
Sample Output
  
  
9 258
 
Statistic |  Submit |  Clarifications |  Back

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1000000+10;
char str[maxn];

bool judge(int k)
{
   sprintf(str,"%d",k);
   int len=strlen(str);
   for(int i=0;i<len/2-1;i++)
      if(str[i+1]<=str[i])  return false;
   if(len%2) if(str[len/2]<=str[len/2-1])  return false;
   for(int i=0;i<len/2;i++)
    {
        if(str[i]!=str[len-i-1]||str[i]=='0'||str[len-i-1]=='0')
             return false;
    }
    return true;
}

int main()
{
    int t,n,ri,cnt;
    scanf("%d",&t);
    while(t--)
    {
        cnt=1;
        ri=1;
        scanf("%d",&n);
        if(n==0)  printf("1\n");
        else
        {
            for(int i=1;i<=n;i++)
                ri=ri*10;
            for(int i=2;i<=ri;i++)
            {
                if(judge(i))
                   {
                      // printf("%d ",i);
                       cnt++;
                   }
            }
            printf("%d\n",cnt);
        }
    }
    return 0;
}

第二题我竟然直接向想暴力,简直too young  too simple。。这题思路是先保存所有操作,然后最后询问的时候我们就逆推这些操作,最后得到要询问的数的下标,那么就引刃而解了,还有一个难点是怎么找出操作后的下标关系,估计这个应该是最难的。其实可以看出,比如1 2 3 4 5 6 7 8   ,那么经过fun1的变换后得到的序列是是1 3 5 7 2 4 6 8,那么可以看出后一半的下标在变换前是(当前位置-一半位置)*2,那么前一半的位置的原来坐标是(当前位置-1)*2+1,,那么逆序操作就好做多了,就是n-id-1,那么就简单了,相当于是离线的操作吧,又长见识了。。。

还有不知道为嘛用int一直wa,longlong就过,不是取余了吗??

题目:

Operation the Sequence


Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 603    Accepted Submission(s): 102


Problem Description
  
  
You have an array consisting of n integers: a1=1,a2=2,a3=3,,an=n . Then give you m operators, you should process all the operators in order. Each operator is one of four types:
Type1: O 1 call fun1();
Type2: O 2 call fun2();
Type3: O 3 call fun3();
Type4: Q i query current value of a[i], this operator will have at most 50.
Global Variables: a[1…n],b[1…n];
fun1() {
index=1;
  for(i=1; i<=n; i +=2)
    b[index++]=a[i];
  for(i=2; i<=n; i +=2)
    b[index++]=a[i];
  for(i=1; i<=n; ++i)
    a[i]=b[i];
}
fun2() {
  L = 1;R = n;
  while(L<R) {
    Swap(a[L], a[R]);
    ++L;--R;
  }
}
fun3() {
  for(i=1; i<=n; ++i)
    a[i]=a[i]*a[i];
}
 
Input
  
  
The first line in the input file is an integer T(1T20) , indicating the number of test cases.
The first line of each test case contains two integer n(0<n100000) , m(0<m100000) .
Then m lines follow, each line represent an operator above.
 
Output
  
  
For each test case, output the query values, the values may be so large, you just output the values mod 1000000007(1e9+7).
 
Sample Input
  
  
1 3 5 O 1 O 2 Q 1 O 3 Q 1
 
Sample Output
  
  
2 4
 
Statistic |  Submit |  Clarifications |  Back

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;

const int maxn=100000+10;
int t,n,m,cnt,b,op[maxn];
ll a[maxn];


ll solve(int cnt,int val)
{
    int half=(n+1)/2;
    ll mul=0;
    for(int i=cnt;i>=1;i--)
    {
        if(op[i]==1)
        {
            if(val>half)  val=(val-half)*2;
            else val=(val-1)*2+1;
        }
        else if(op[i]==2)
            val=n-val+1;
        else
            mul++;
    }
    ll ans=a[val];
    for(int i=1;i<=mul;i++)
         ans=ans*ans%mod;
	return ans;
}

int main()
{
    char s[2];
    scanf("%d",&t);
    while(t--)
    {
        cnt=0;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++) a[i]=i;
        while(m--)
        {
            scanf("%s%d",s,&b);
            if(s[0]=='O')
               op[++cnt]=b;
            else
            {
                ll ans=solve(cnt,b);
                printf("%I64d\n",ans);
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值