设为首页 加入收藏

TOP

BestCoder Round #13(前两题)
2015-07-20 17:28:18 来源: 作者: 【 】 浏览:2
Tags: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 
  
   (a1a2…akak…a2a1)10
   or 
  
   (a1a2…ak?1akak?1…a2a1)10
   of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies 
  
   0
   
    , 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(1≤T≤7)
  , indicating the number of test cases.
Then T lines follow, each line represent an integer N(0≤N≤6) .
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
  
   
#include
   
     #include
    
      #include
     
       #include
       #include
       
         #include
        
          #include
         
           #include
          
            #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
           
            
第二题我竟然直接向想暴力,简直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 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(1≤T≤20)
             , indicating the number of test cases.
The first line of each test case contains two integer n(0 , m(0 .
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
              
               
#include
               
                 #include
                
                  #include
                 
                   #include
                   #include
                   
                     #include
                    
                      #include
                     
                       #include
                      
                        #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; } 
                      
                     
                    
                   
                 
                
               
              


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3984 迷宫问题 下一篇HDU 4756 Install Air Conditioni..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)