zoukankan      html  css  js  c++  java
  • CDQZ Day4

    NOIP 模拟题
    By liu_runda
    题目名称 数 论 题
    源程序文件名 number.cpp theory.cpp problem.cpp
    输入文件名 number.in theory.in problem.in
    输出文件名 number.out theory.out problem.out
    每个测试点时限 1s 1s 1s
    内存限制 512MB 512MB 512MB
    测试点数目 10 10 20
    每个测试点分值 10 10 5
    是否打开O2 优化 否 否 否
    数(number)
    【题目描述】
    给出n 个正整数,分别判断每个正整数是不是质数.
    【输入格式】
    第一行一个整数n 表示正整数的数目. 接下来n 行,第i+1 行一个整数ai.
    【输出格式】
    n 行,对于第i 行,如果ai 是质数,输出一行”YES”(不含引号),否则输出一行”NO”(不含引号).
    【样例输入】
    5
    1
    2
    3
    4
    5
    【样例输出】
    NO
    YES
    YES
    NO
    YES
    【数据范围】
    对于10%的数据,n=1
    对于50%的数据,1<=ai<=10^5
    对于100%的数据,1<=n<=100,1<=ai<=10^9
    论(theory)
    【题目描述】
    给出一个正整数n,求gcd(1,n)+gcd(2,n)+gcd(3,n)+...+gcd(n,n),即1 到n 每个数和n 的最大
    公约数之和.
    gcd(a,b)表示a 和b 的最大公约数,即一个最大的整数x 使得x 既是a 的约数.也是b 的约
    数.
    【输入格式】
    一行一个整数n
    【输出格式】
    一行一个整数ans,表示答案
    【样例输入】
    11
    【样例输出】
    21
    【数据范围】
    对于30%的数据,n<=100
    对于60%的数据,n<=1000000
    对于80%的数据,n<=10000000
    对于100%的数据,n<=100000000
    题(problem)
    【题目描述】
    你在平面直角坐标系上.
    你一开始位于(0,0).
    每次可以在上/下/左/右四个方向中选一个走一步.
    即:从(x,y)走到(x,y+1),(x,y-1),(x-1,y),(x+1,y)四个位置中的其中一个.
    允许你走的步数已经确定为n.现在你想走n 步之后回到(0,0).但这太简单了.你希望知道
    有多少种不同的方案能够使你在n 步之后回到(0,0).当且仅当两种方案至少有一步走的方向
    不同,这两种方案被认为是不同的.
    答案可能很大所以只需要输出答案对10^9+7 取模后的结果.(10^9+7=1000000007,1 和7
    之间有8 个0)
    这还是太简单了,所以你给能够到达的格点加上了一些限制.一共有三种限制,加上没有
    限制的情况,一共有四种情况,用0,1,2,3 标号:
    0.没有任何限制,可以到达坐标系上所有的点,即能到达的点集为{(x,y)|x,y 为整数}
    1.只允许到达x 轴非负半轴上的点.即能到达的点集为{(x,y)|x 为非负数,y=0}
    2.只允许到达坐标轴上的点.即能到达的点集为{(x,y)|x=0 或y=0}
    3.只允许到达x 轴非负半轴上的点,y 轴非负半轴上的点以及第1 象限的点.即能到达的点
    集为{(x,y)|x>=0,y>=0}
    【输入格式】
    一行两个整数(空格隔开)n 和typ,分别表示你必须恰好走的步数和限制的种类.typ 的含
    义见【题目描述】.
    【输出格式】
    一行一个整数ans,表示不同的方案数对10^9+7 取模后的结果.
    【样例输入0】
    100 0
    【样例输出0】
    383726909
    【样例输入1】
    100 1
    【样例输出1】
    265470434
    【样例输入2】
    100 2
    【样例输出2】
    376611634
    【样例输入3】
    100 3
    【样例输出3】
    627595255
    【数据范围】
    10%的数据,typ=0,n<=100
    10%的数据,typ=0,n<=1000
    5%的数据, typ=0,n<=100000
    10%的数据,typ=1,n<=100
    10%的数据,typ=1,n<=1000
    5%的数据, typ=1,n<=100000
    10%的数据,typ=2,n<=100
    15%的数据,typ=2,n<=1000
    10%的数据,typ=3,n<=100
    10%的数据,typ=3,n<=1000
    5%的数据, typ=3,n<=100000
    以上11 部分数据没有交集.
    100%的数据,保证n 为偶数,2<=n<=100000,0<=typ<=3.

      1 #include<cstdio>
      2 #include<cstring>
      3 #include<iostream>
      4 #include<algorithm>
      5 #include<cmath>
      6 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
      7 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
      8 #define Ii inline int
      9 #define Iv inline void
     10 #define Il inline long long
     11 #define Ib inline bool
     12 #define re register
     13 #define ll long long
     14 #define D_e_Line printf("
    -------------
    ")
     15 #define D_e(x) printf("
    ______%d_______
    ",x)
     16 #define Pause system("pause")
     17 using namespace std;
     18 Ii read(){
     19     int s=0,f=1;char c;
     20     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
     21     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
     22     return s*f;
     23 }
     24 Iv print(int x){
     25     if(x<0)putchar('-'),x=-x;
     26     if(x>9)print(x/10);
     27     putchar(x%10^'0');
     28 }
     29 const int mod=1000000007;
     30 ll cat[100005];
     31 Il Pow(ll a,ll b){
     32     ll s=1;
     33     a%=mod,b%=mod; 
     34     while(b){
     35         if(b&1)s=s*a%mod;
     36         a=a*a%mod,b>>=1; 
     37     }
     38     //D_e(s%mod);
     39     return s%mod;
     40 }
     41 Il Smul(ll a,ll b){
     42     ll s=0;
     43     a%=mod,b%=mod;
     44     while(b){
     45         if(b&1)s=(s+a)%mod;
     46         a=(a+a)%mod,b>>=1;
     47     }
     48     return s%mod;
     49 }
     50 Iv Catalan(int &x){
     51     x>>=1,
     52     cat[0]=1,cat[1]=1;
     53     R(i,2,x){
     54         cat[i]=Smul(Smul(cat[i-1],4*i-2)%mod,Pow(i+1,mod-2))%mod;
     55         //D_e(cat[i])
     56         //cout<<cat[i]<<endl;
     57     }
     58 }
     59 Iv Work(int &n){
     60     if(n==0){putchar('0');return;}
     61     Catalan(n);
     62     //printf("%d
    ",(cat[n+1]%mod+mod)%mod-(cat[n]%mod+mod)%mod);
     63     printf("%d",(cat[n]%mod+mod)%mod);
     64 }
     65 int anss[]={1,2,10,70,588,5544,56628,613470,6952660,81662152};
     66 #define ON_JUDGE
     67 int main(){
     68 #ifdef ON_JUDGE
     69     freopen("problem.in","r",stdin),freopen("problem.out","w",stdout);
     70 #endif
     71     int n=read();
     72     int opt=read();
     73     if(opt==2){
     74         if(n==0){
     75             printf("0");return 0;    
     76         }
     77         printf("%d
    ",anss[n-1]);return 0;
     78     }
     79     Work(n);
     80     return 0;
     81 }
     82 /*
     83 1
     84 1
     85 2
     86 5
     87 14
     88 42
     89 132
     90 429
     91 1430
     92 4862
     93 16796
     94 58786
     95 208012
     96 742900
     97 2674440
     98 9694845
     99 35357670
    100 129644790
    101 477638700
    102 
    103 
    104 1
    105 2
    106 10
    107 70
    108 588
    109 5544
    110 56628
    111 613470
    112 6952660
    113 81662152
    114 
    115 
    116 */
    problem_my_CreatOnContest.cpp
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cmath>
     6 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
     7 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
     8 #define Ii inline int
     9 #define Iv inline void
    10 #define Il inline long long
    11 #define Ib inline bool
    12 #define re register
    13 #define ll long long
    14 #define D_e_Line printf("
    -------------
    ");
    15 #define D_e(x) printf("
    ______%d_______
    ",x)
    16 #define Pause system("pause")
    17 using namespace std;
    18 Ii read(){
    19     int s=0,f=1;char c;
    20     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
    21     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
    22     return s*f;
    23 }
    24 Ii gcd(int a,int b){
    25     while(b^=a^=b^=a%=b);return a;
    26 }
    27 Iv print(ll x){
    28     if(x<0)putchar('-'),x=-x;
    29     if(x>9)print(x/10);
    30     putchar(x%10^'0');
    31 }
    32 #define ON_JUDGE
    33 int main(){
    34 #ifdef ON_JUDGE
    35     freopen("theory.in","r",stdin),freopen("theory.out","w",stdout);
    36 #endif
    37     //cout<<sizeof(ans)/4<<endl;
    38     int n=read();
    39     ll ans=0;
    40     R(i,1,n)
    41         ans+=gcd(i,n);
    42     print(ans);
    43     return 0;
    44 }
    theory_my_CreatOnContest
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cmath>
     6 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
     7 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
     8 #define Ii inline int
     9 #define Iv inline void
    10 #define Il inline long long
    11 #define Ib inline bool
    12 #define re register
    13 #define ll long long
    14 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
    15 #define D_e_Line printf("
    -------------
    ");
    16 #define D_e(x) printf("
    ______%d_______
    ",x)
    17 #define Pause system("pause")
    18 using namespace std;
    19 Ii read(){
    20     int s=0,f=1;char c;
    21     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
    22     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
    23     return s*f;
    24 }
    25 Iv print(ll x){
    26     if(x<0)putchar('-'),x=-x;
    27     if(x>9)print(x/10);
    28     putchar(x%10^'0');
    29 }
    30 Ii Phi(int x){
    31     int sum=x;
    32     for(re int i=2;i*i<=x;++i)
    33         if(x%i==0){
    34             sum-=sum/i;
    35             while(x%i==0)x/=i;
    36         }
    37     return x!=1?sum-sum/x:sum;
    38 }
    39 Il Cal(int d,int n){
    40       return (ll)Phi(n/d)*d;
    41 }
    42 int main(){
    43       freopen("theory.in","r",stdin),freopen("theory.out","w",stdout);
    44     int n=read();
    45     ll ans=0;
    46     for(re int i=1;i*i<=n;++i)
    47         if(n%i==0){
    48               ans+=Cal(i,n);
    49               if(i*i<n)
    50                   ans+=Cal(n/i,n);
    51         }
    52     print(ans);
    53       return 0;
    54 }
    theory_AC.cpp
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cmath>
     6 #define R(a,b,c) for(register int (a)=(b);(a)<=(c);++(a))
     7 #define nR(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
     8 #define Ii inline int
     9 #define Iv inline void
    10 #define Il inline long long
    11 #define Ib inline bool
    12 #define re register
    13 #define ll long long
    14 #define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
    15 #define D_e_Line printf("
    -------------
    ");
    16 #define D_e(x) printf("
    ______%d_______
    ",x)
    17 #define Pause system("pause")
    18 using namespace std;
    19 const int N=200005;
    20 const int mod=1000000007;
    21 Il read(){
    22     ll s=0,f=1;char c;
    23     for(c=getchar();c>'9'||c<'0';c=getchar())if(c=='-')f=-1;
    24     while(c>='0'&&c<='9')s=s*10+(c^'0'),c=getchar();
    25     return s*f;
    26 }
    27 Iv print(ll x){
    28     if(x<0)putchar('-'),x=-x;
    29     if(x>9)print(x/10);
    30     putchar(x%10^'0');
    31 }
    32 int fac[N],invfac[N];
    33 Ii C(int n,int m){
    34       if(n<m)return 0;
    35       return (ll)fac[n]*invfac[m]%mod*invfac[n-m]%mod;
    36 }
    37 Ii Pow(int a,int b){
    38     int s=1;
    39     a%=mod,b%=mod; 
    40     while(b){
    41         if(b&1)s=(ll)s*a%mod;
    42         a=(ll)a*a%mod,b>>=1;
    43     }
    44     return s%mod;
    45 }
    46 Ii Catalan(int n){
    47   return (ll)C(n<<1,n)*Pow(n+1,mod-2)%mod;
    48 }
    49 Iv Init(){
    50     fac[0]=1;
    51     R(i,1,N)
    52         fac[i]=(ll)(fac[i-1])*i%mod;
    53     invfac[N-1]=Pow(fac[N-1],mod-2);
    54     nR(i,N-1,1)
    55         invfac[i-1]=(ll)(invfac[i])*i%mod;
    56 }
    57 int f[N];
    58 int main(){
    59   //freopen("problem.in","r",stdin),freopen("problem.out","w",stdout);
    60     Init();
    61     int n=read();
    62     switch(read()){
    63         case 0:{
    64             ll ans=0;
    65             for(re int i=0;i<=n;i+=2)
    66                   ans=(ll)((ans+C(n,i))*C(i,i>>1)%mod*C((n-i),(n-i)>>1)%mod)%mod;
    67               //ans=(C(n,n>>1)%mod)*(C(n,n>>1)%mod)%mod;
    68             print(ans);break;
    69         }
    70         case 1:{
    71             printf("%d
    ",Catalan(n>>1));break;
    72         }
    73         case 2:{
    74             n>>=1,
    75             f[0]=1,f[1]=4;
    76             R(i,2,n)
    77                   R(j,1,i)
    78                     f[i]=((ll)(f[i]+f[i-j]*4)*Catalan(j-1)%mod)%mod;
    79             print(f[n]);break;
    80         }
    81         default:{
    82             int ans=0;
    83             for(re int i=0;i<=n;i+=2)
    84                   ans=(ans+(ll)(C(n,i))*Catalan(i>>1)%mod*Catalan((n-i)>>1)%mod)%mod;
    85             print(ans);break;
    86         }
    87     }    
    88       return 0;
    89 }
    problem_WA.cpp
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <queue>
     7 #include <bitset>
     8 
     9 #define Min(a,b) ((a)<(b)?(a):(b))
    10 #define Max(a,b) ((a)>(b)?(a):(b))
    11 #define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
    12 #define Abs(a) (a)>0?(a):(-(a))
    13 template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
    14 template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
    15 template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}
    16 
    17 #define inf 0x7f7f7f7f
    18 #define dinf 0x3f3f3f3f
    19 #define llinf 0x7f7f7f7f7f7f7f7f
    20 #define lldinf 0x3f3f3f3f3f3f3f3f
    21 
    22 #define ll long long
    23 #define rei register int
    24 #define inv inline void
    25 #define inb inline bool
    26 #define ini inline int
    27 
    28 #define bl putchar(' ')
    29 #define ed putchar('
    ')
    30 #define test std::cout<<"this:"
    31 #define card system("pause")
    32 
    33 #define read2(a,b) read(a),read(b)
    34 #define read3(a,b,c) read(a),read(b),read(c)
    35 
    36 #define MAXN 100005
    37 #define MAXM 100005
    38 
    39 char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
    40 #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    41 
    42 template <typename QvQ>inv read(QvQ &x)
    43 {
    44     x=0;int f=1;
    45     char c=getchar();
    46     for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
    47     for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
    48     x=x*f;
    49 }
    50 template <typename QvQ>inv write(QvQ x)
    51 {
    52     if(x<0) x=-x,putchar('-');
    53     if(x>9) write(x/10);
    54     putchar(x%10+'0');
    55 }
    56 int n,q,cnt,len;
    57 ll val,ans,a[MAXN],sum[MAXN/100],lazy[MAXN/100];
    58 int piece[MAXN],left[MAXN/100],right[MAXN/100];
    59 inv build()
    60 {
    61     memset(lazy,0,sizeof(lazy));
    62     read2(n,q);
    63     len=sqrt(n);
    64     cnt=n/len;
    65     if(n%len) ++cnt;
    66     for(rei i=1;i<=n;++i) read(*(a+i)),*(piece+i)=(i-1)/len+1,sum[*(piece+i)]+=*(a+i);
    67     for(rei i=1;i<=cnt;++i) *(left+i)=(i-1)*len+1,*(right+i)=i*len;
    68     
    69 }
    70 int main()
    71 {
    72     build();
    73     int willing;
    74     while(q--)
    75     {
    76         int l,r;
    77         read3(willing,l,r);
    78         if(willing==1)
    79         {
    80             int val;read(val);
    81             for(rei i=l;i<=Min(r,*(right+*(piece+l)));++i) a[i]+=val,sum[piece[i]]+=val;
    82             for(rei i=r;i>=Max(l,*(left+*(piece+r)));--i) a[i]+=val,sum[piece[i]]+=val;
    83             for(rei i=piece[l]+1;i<=piece[r]-1;++i) lazy[i]+=val;
    84         }
    85         else
    86         {
    87             ans=0;
    88             for(rei i=l;i<=Min(r,*(right+*(piece+l)));++i) ans+=a[i]+lazy[piece[i]];
    89             for(rei i=r;i>=Max(l,*(left+*(piece+r)));--i) ans+=a[i]+lazy[piece[i]];
    90             for(rei i=piece[l]+1;i<=piece[r]-1;++i) ans+=sum[i]+lazy[i]*(right[i]-left[i]+1);
    91             if(piece[l]==piece[r]) ans-=a[l]+lazy[piece[l]]+lazy[piece[r]]+a[r];
    92             write(ans),ed;
    93         }
    94     }
    95     return 0;
    96 }
    problem_STD.cpp
  • 相关阅读:
    [转载]android开发手册
    [转载]windows phone7 学习笔记10——生命周期/墓碑化
    [转载]Windows Phone 系列 本地数据存储
    【转载】windows phone7 学习笔记12——推送通知服务
    【转载】windows phone7 学习笔记15——Bing Maps
    [转载]WP7交互特性浅析及APP设计探究
    【】windows phone7 学习笔记11——启动器与选择器
    [转载]支持的 Windows Phone 媒体编解码器
    【转载】wp7屏幕截图代码
    【转载】windows phone7 学习笔记14——地理位置服务与反应性扩展框架
  • 原文地址:https://www.cnblogs.com/bingoyes/p/10321224.html
Copyright © 2011-2022 走看看