A
手动打表做出映射关系...然后八进制转十进制..
Program:
- #include<iostream>
- #include<stdio.h>
- #include<algorithm>
- #include<string.h>
- #include<math.h>
- #include<map>
- #include<queue>
- #include<stack>
- #define ll long long
- #define oo 1000000000
- #define pi acos(-1)
- using namespace std;
- ll ans,n,m,k,a[10]={0,1,2,0,3,4,5,6,0,7};
- int main()
- {
- // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
- while (~scanf("%I64d",&n))
- {
- if (!n) break;
- m=n; ans=0; k=1;
- while (n)
- {
- ans+=a[n%10]*k;
- n/=10;
- k*=8;
- }
- printf("%I64d: %I64d\n",m,ans);
- }
- return 0;
- }
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#define ll long long
#define oo 1000000000
#define pi acos(-1)
using namespace std;
ll ans,n,m,k,a[10]={0,1,2,0,3,4,5,6,0,7};
int main()
{
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
while (~scanf("%I64d",&n))
{
if (!n) break;
m=n; ans=0; k=1;
while (n)
{
ans+=a[n%10]*k;
n/=10;
k*=8;
}
printf("%I64d: %I64d\n",m,ans);
}
return 0;
}
B
这种题目的第一直觉就是找规律...打出前面一些sum...不难发现当k>12时..在0~k间的real number要么是k/2-1要么是k/2-2...那关键就在于寻找什么时候是-1,什么时候是-2...通过观察可以发现... 每逢平方数...-1,-2就会转变... 并且当 p^2 <= k < (p+1)^2 时..当p为奇数...0~k的real number为k/2-1...p为偶数...其为k/2-2....
能快速得到0~k间real number的个数..剩下的就简单了....
Program:
- #include<iostream>
- #include<stdio.h>
- #include<algorithm>
- #include<string.h>
- #include<math.h>
- #include<map>
- #include<queue>
- #include<stack>
- #define ll long long
- #define oo 1000000000
- #define pi acos(-1)
- using namespace std;
- int t,n,s[20]={0,0,0,0,0,0,1,1,2,3,4,4,5};
- ll a,b,p1,p2;
- ll getsum(ll x)
- {
- if (x<=12) return s[x];
- ll m,k;
- m=x/2;
- k=(ll)sqrt(x);
- if (k%2==0) m-=2;
- else m-=1;
- return m;
- }
- int main()
- {
- // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
- scanf("%d",&t);
- while (t--)
- {
- scanf("%I64d%I64d",&a,&b);
- a--;
- p1=getsum(a);
- p2=getsum(b);
- printf("%I64d\n",p2-p1);
- }
- return 0;
- }
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#define ll long long
#define oo 1000000000
#define pi acos(-1)
using namespace std;
int t,n,s[20]={0,0,0,0,0,0,1,1,2,3,4,4,5};
ll a,b,p1,p2;
ll getsum(ll x)
{
if (x<=12) return s[x];
ll m,k;
m=x/2;
k=(ll)sqrt(x);
if (k%2==0) m-=2;
else m-=1;
return m;
}
int main()
{
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
scanf("%d",&t);
while (t--)
{
scanf("%I64d%I64d",&a,&b);
a--;
p1=getsum(a);
p2=getsum(b);
printf("%I64d\n",p2-p1);
}
return 0;
}
J
我是用trie树做的...直接用数组标记或者用map也能很和谐吧...
- #include<iostream>
- #include<stdio.h>
- #include<algorithm>
- #include<string.h>
- #include<math.h>
- #include<map>
- #include<queue>
- #include<stack>
- #define ll long long
- #define oo 1000000000
- #define pi acos(-1)
- using namespace std;
- struct node
- {
- int son[10],w;
- }p[600005];
- int ans,t,n,m,g,c[27]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
- char s[5005][10],str[10];
- int main()
- {
- // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
- scanf("%d",&t);
- while (t--)
- {
- int i,h,k,len;
- scanf("%d%d",&n,&m);
- for (i=1;i<=n;i++) scanf("%s",s[i]);
- memset(p,0,sizeof(p));
- g=0;
- while (m--)
- {
- scanf("%s",str);
- len=strlen(str);
- h=0;
- for (i=0;i<len;i++)
- {
- if (!p[h].son[c[str[i]-'a']]) p[h].son[c[str[i]-'a']]=++g;
- h=p[h].son[c[str[i]-'a']];
- }
- p[h].w++;
- }
- for (k=1;k<=n;k++)
- {
- len=strlen(s[k]);
- ans=h=0;
- for (i=0;i<len;i++)
- {
- if (!p[h].son[s[k][i]-'0']) break;
- h=p[h].son[s[k][i]-'0'];
- }
- if (i==len) ans=p[h].w;
- printf("%d\n",ans);
- }
- }
- return 0;
- }