程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> BestCoder Round #13(前兩題)

BestCoder Round #13(前兩題)

編輯:C++入門知識

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;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved