这一次又只出了一题,第二题没有分析好,竟然直接copy代码,不过长见识了。。
第一题给了一些限制条件,自己没有分析好,就去乱搞,结果各种不对,后来有读题才发现。。暴力乱搞。。
题目:
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 satisfies0<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 and10N .
The first line in the input file is an integerT(1≤T≤7) , indicating the number of test cases.
Then T lines follow, each line represent an integerN(0≤N≤6) .
For each test case, output the number of Beautiful Palindrome Number.
2 1 6
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;
}
还有不知道为嘛用int一直wa,longlong就过,不是取余了吗??
题目:
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];
}
The first line in the input file is an integerT(1≤T≤20) , indicating the number of test cases.
The first line of each test case contains two integern(0<n≤100000) ,m(0<m≤100000) .
Then m lines follow, each line represent an operator above.
For each test case, output the query values, the values may be so large, you just output the values mod 1000000007(1e9+7).
1 3 5 O 1 O 2 Q 1 O 3 Q 1
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;
}
原文:http://blog.csdn.net/u014303647/article/details/40118915