这一次又只出了一题,第二题没有分析好,竟然直接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<a1<a2<…<ak≤9 , 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
#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(1≤T≤20) , indicating the number of test cases.
The first line of each test case contains two integer n(0<n≤100000) , m(0<m≤100000) .
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
#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;
}