The 37th ACM/ICPC Asia Regional Tianjin Site Online Contest - A.B.J

A

  手动打表做出映射关系...然后八进制转十进制..


Program:

  1. #include<iostream> 
  2. #include<stdio.h> 
  3. #include<algorithm> 
  4. #include<string.h> 
  5. #include<math.h> 
  6. #include<map> 
  7. #include<queue> 
  8. #include<stack> 
  9. #define ll long long 
  10. #define oo 1000000000 
  11. #define pi acos(-1) 
  12. using namespace std;       
  13. ll ans,n,m,k,a[10]={0,1,2,0,3,4,5,6,0,7}; 
  14. int main() 
  15. {  
  16.   //   freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);  
  17.      while (~scanf("%I64d",&n)) 
  18.      {     
  19.            if (!n) break
  20.            m=n;  ans=0;  k=1; 
  21.            while (n) 
  22.            { 
  23.                  ans+=a[n%10]*k; 
  24.                  n/=10; 
  25.                  k*=8; 
  26.            } 
  27.            printf("%I64d: %I64d\n",m,ans);  
  28.      } 
  29.      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:

  1. #include<iostream> 
  2. #include<stdio.h> 
  3. #include<algorithm> 
  4. #include<string.h> 
  5. #include<math.h> 
  6. #include<map> 
  7. #include<queue> 
  8. #include<stack> 
  9. #define ll long long 
  10. #define oo 1000000000 
  11. #define pi acos(-1) 
  12. using namespace std;       
  13. int t,n,s[20]={0,0,0,0,0,0,1,1,2,3,4,4,5};    
  14. ll a,b,p1,p2; 
  15. ll getsum(ll x) 
  16.      if (x<=12) return s[x]; 
  17.      ll m,k; 
  18.      m=x/2;  
  19.      k=(ll)sqrt(x); 
  20.      if (k%2==0) m-=2; 
  21.         else m-=1; 
  22.      return m; 
  23. int main() 
  24. {   
  25.     // freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);  
  26.      scanf("%d",&t); 
  27.      while (t--) 
  28.      {  
  29.             scanf("%I64d%I64d",&a,&b); 
  30.             a--; 
  31.             p1=getsum(a);   
  32.             p2=getsum(b); 
  33.             printf("%I64d\n",p2-p1); 
  34.      } 
  35.      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也能很和谐吧...

  1. #include<iostream> 
  2. #include<stdio.h> 
  3. #include<algorithm> 
  4. #include<string.h> 
  5. #include<math.h> 
  6. #include<map> 
  7. #include<queue> 
  8. #include<stack> 
  9. #define ll long long 
  10. #define oo 1000000000 
  11. #define pi acos(-1) 
  12. using namespace std;       
  13. struct node 
  14.      int son[10],w; 
  15. }p[600005]; 
  16. 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}; 
  17. char s[5005][10],str[10]; 
  18. int main() 
  19. {  
  20.     // freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);  
  21.      scanf("%d",&t); 
  22.      while (t--) 
  23.      {     
  24.              int i,h,k,len; 
  25.              scanf("%d%d",&n,&m); 
  26.              for (i=1;i<=n;i++) scanf("%s",s[i]); 
  27.              memset(p,0,sizeof(p)); 
  28.              g=0; 
  29.              while (m--) 
  30.              { 
  31.                     scanf("%s",str); 
  32.                     len=strlen(str); 
  33.                     h=0; 
  34.                     for (i=0;i<len;i++) 
  35.                     { 
  36.                            if (!p[h].son[c[str[i]-'a']]) p[h].son[c[str[i]-'a']]=++g; 
  37.                            h=p[h].son[c[str[i]-'a']]; 
  38.                     } 
  39.                     p[h].w++; 
  40.              } 
  41.              for (k=1;k<=n;k++) 
  42.              { 
  43.                     len=strlen(s[k]); 
  44.                     ans=h=0; 
  45.                     for (i=0;i<len;i++) 
  46.                     { 
  47.                            if (!p[h].son[s[k][i]-'0']) break
  48.                            h=p[h].son[s[k][i]-'0']; 
  49.                     } 
  50.                     if (i==len) ans=p[h].w; 
  51.                     printf("%d\n",ans); 
  52.              } 
  53.      } 
  54.      return 0; 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值