zoukankan      html  css  js  c++  java
  • hdu 多校 2018 第十场

    1001 OI业界毒瘤题(把收藏已久的blog拿出来就好了,反正现场赛也不会写(逃

    1004 BPM136 是不是dls写的题解啊,什么是转移很显然啊( 

    f_i_j_k 表示考虑前i个位置,有j条出边,j条入边,权值为k的个数(就是看成点i向pi连边,连abs(i-pi)的边,那么一定是一堆的环)

    转移的时候,因为有j条边没有搞定,所以每次权值往k+j转移,因为这些边的距离又远了1

    然后要么自己结束一条边,要么自己用未来的点连,那么多出一条边,或者是自己自交(雾

    这么看的话转移就真的很显然啦qwqqqqqqqq

     1 #define get(a,i) ((a)&(1<<(i-1)))
     2 #define PAU putchar(32)
     3 #define ENT putchar(10)
     4 #define all(x) ((int) (x).size())
     5 #define clr(a,b) memset(a,b,sizeof(a))
     6 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     7 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     8 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     9 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
    10 #define Remax(a,b) if(b>a) a=b;
    11 #define Remin(a,b) if(b<a) a=b;
    12 #define SZ(x) ((int)(x).size())
    13 #define filein(x) freopen(#x".in","r",stdin)
    14 #define fileout(x) freopen(#x".out","w",stdout)
    15 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
    16 #define mkd(x) freopen(#x".in","w",stdout);
    17 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(_SIZE)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
    18 #define END system("pause")
    19 #define read2(a,b) read(a),read(b)
    20 #define read3(a,b,c) read(a),read(b),read(c)
    21 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
    22 #define use_cin_cout cin.sync_with_stdio(0),cout.sync_with_stdio(0),cerr.sync_with_stdio(0)
    23 using namespace std;
    24 
    25 typedef long long ll;
    26 typedef double DB;
    27 typedef long double LD;
    28 typedef unsigned int  UI;
    29 typedef unsigned long long ULL;
    30 typedef vector<int> VI;
    31 typedef vector<ll> VLL;
    32 typedef set<int> SI;
    33 typedef set<ll> SLL;
    34 typedef set<int , greater<int> > SIG;
    35 typedef set<ll , greater<ll> > SLLG;
    36 typedef map<int, int > MII;
    37 typedef map<int, int, greater<int> > MIIG;
    38 typedef map<ll, ll > MLLLL;
    39 typedef map<ll, ll, greater<ll> > MLLLLG;
    40 
    41 const int N = 105;
    42 
    43 int f[2][N][N * N];
    44 int n,MOD;
    45 
    46 int main() {
    47     use_cin_cout;
    48     int T; cin >> T;
    49     while(T --) {
    50         cin >> n >> MOD;
    51         
    52         clr(f, 0);
    53         int now = 0;
    54         f[now][0][0] = 1; f[now][1][0] = 1;
    55         rep(i, 1, n - 1) {
    56             now = 1 - now;
    57             clr(f[now], 0);
    58             rep(j, 0, i) rep(k, 0, i * i) if(f[j][k] > 0) {
    59                 (f[now][j][k + j] += (ll) (2 * j + 1) * f[1 - now][j][k] % MOD) %= MOD;
    60                 if(j - 1 >= 0) (f[now][j - 1][k + j] += (ll) j * j * f[1 - now][j][k] % MOD) %= MOD;
    61                 (f[now][j + 1][k + j] += f[1 - now][j][k]) %= MOD;
    62             }
    63         }
    64         cout << f[now][0][0];
    65         rep(i, 1, n * n - 1) {
    66             cout << ' ';
    67             if(i & 1) cout << 0; else cout << f[now][0][i / 2];
    68         }
    69         cout << '
    ';
    70     }
    71     return 0;
    72 }
    View Code

    1005 BPM136  考虑从大到小枚举每一个答案,把可能是答案的点构造一棵虚树(并不用完全建出来),那么虚树上所有不是叶子节点的点答案就是你枚举的答案(找的虚树板子居然没写lca为根的情况,还是要自己整理板子才行

      1 /* ***********************************************
      2 Author        :BPM136
      3 Created Time  :2018/8/22 13:21:06
      4 File Name     :1005.cpp
      5 ************************************************ */
      6 
      7 #include<iostream>
      8 #include<cstdio>
      9 #include<algorithm>
     10 #include<cstdlib>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<iomanip>
     14 #include<bitset>
     15 #include<queue>
     16 #include<ctime>
     17 #include<set>
     18 #include<map>
     19 #include<list>
     20 #include<vector>
     21 #include<cassert>
     22 #include<functional>
     23 #include<string>
     24 #define pb push_back
     25 #define popb pop_back
     26 #define MID ((l+r)>>1)
     27 #define LSON (k<<1)
     28 #define RSON (k<<1|1)
     29 #define get(a,i) ((a)&(1<<(i-1)))
     30 #define PAU putchar(32)
     31 #define ENT putchar(10)
     32 #define all(x) ((int) (x).size())
     33 #define clr(a,b) memset(a,b,sizeof(a))
     34 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     35 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     36 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     37 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
     38 #define Remax(a,b) if(b>a) a=b;
     39 #define Remin(a,b) if(b<a) a=b;
     40 #define SZ(x) ((int)(x).size())
     41 #define filein(x) freopen(#x".in","r",stdin)
     42 #define fileout(x) freopen(#x".out","w",stdout)
     43 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
     44 #define mkd(x) freopen(#x".in","w",stdout);
     45 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(_SIZE)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     46 #define END system("pause")
     47 #define read2(a,b) read(a),read(b)
     48 #define read3(a,b,c) read(a),read(b),read(c)
     49 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     50 #define use_cin_cout cin.sync_with_stdio(0),cout.sync_with_stdio(0),cerr.sync_with_stdio(0)
     51 using namespace std;
     52 
     53 typedef long long ll;
     54 typedef double DB;
     55 typedef long double LD;
     56 typedef unsigned int  UI;
     57 typedef unsigned long long ULL;
     58 typedef vector<int> VI;
     59 typedef vector<ll> VLL;
     60 typedef set<int> SI;
     61 typedef set<ll> SLL;
     62 typedef set<int , greater<int> > SIG;
     63 typedef set<ll , greater<ll> > SLLG;
     64 typedef map<int, int > MII;
     65 typedef map<int, int, greater<int> > MIIG;
     66 typedef map<ll, ll > MLLLL;
     67 typedef map<ll, ll, greater<ll> > MLLLLG;
     68 
     69 namespace fastIO{  
     70     #define BUF_SIZE 100000  
     71     #define OUT_SIZE 100000  
     72     //fread->read  
     73     bool IOerror=0;  
     74     inline char nc(){  
     75         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     76         if (p1==pend){  
     77             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     78             if (pend==p1){IOerror=1;return -1;}  
     79             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     80         }  
     81         return *p1++;  
     82     }  
     83     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     84     inline bool enter(char ch){return ch==10||ch==13;}
     85     inline void read(int &x){  
     86         bool sign=0; char ch=nc(); x=0;  
     87         for (;blank(ch);ch=nc());  
     88         if (IOerror)return;  
     89         if (ch==45)sign=1,ch=nc();  
     90         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     91         if (sign)x=-x;  
     92     }  
     93     inline void read(ll &x){  
     94         bool sign=0; char ch=nc(); x=0;  
     95         for (;blank(ch);ch=nc());  
     96         if (IOerror)return;  
     97         if (ch==45)sign=1,ch=nc();  
     98         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     99         if (sign)x=-x;  
    100     }  
    101     inline void read(double &x){  
    102         bool sign=0; char ch=nc(); x=0;  
    103         for (;blank(ch);ch=nc());  
    104         if (IOerror)return;  
    105         if (ch==45)sign=1,ch=nc();  
    106         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
    107         if (ch==46){  
    108             double tmp=1; ch=nc();  
    109             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
    110         }  
    111         if (sign)x=-x;  
    112     }  
    113     inline void read(char *s){  
    114         char ch=nc();  
    115         for (;blank(ch);ch=nc());  
    116         if (IOerror)return;  
    117         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    118         *s=0;  
    119     }  
    120     inline void read(char *s,bool f) {
    121         char ch=nc();
    122         for (;blank(ch);ch=nc());
    123         if(IOerror)return;
    124         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
    125         *s=0;
    126     }
    127     inline void read(char &c){  
    128         for (c=nc();blank(c);c=nc());  
    129         if (IOerror){c=-1;return;}  
    130     } 
    131 #undef OUT_SIZE  
    132 #undef BUF_SIZE  
    133 }; using namespace fastIO;
    134 
    135 const int N = 100005;
    136 const int LOGN = 20;
    137 
    138 struct edge {
    139     int y,next;
    140 }e[N],_e[N];
    141 int last[N],ne;
    142 int ans[N];
    143 int n;
    144 
    145 void add(int x,int y) {
    146     e[++ne].y=y; e[ne].next=last[x]; last[x]=ne;
    147 }
    148 
    149 
    150 VI tot[N];
    151 
    152 int fa[N][LOGN];
    153 int dep[N];
    154 int dfn[N],timed=0;
    155 int get_lca(int x,int y) {
    156     if(dep[x]<dep[y]) swap(x,y);
    157     for(int i=LOGN-1;i>=0;i--) if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
    158     if(x==y) return x;
    159     for(int i=LOGN-1;i>=0;i--) if(fa[x][i]!=fa[y][i]) {
    160         x=fa[x][i];
    161         y=fa[y][i];
    162     }
    163     return fa[x][0];
    164 }
    165 void dfs(int x) {
    166     dfn[x]=++timed;
    167     for(int i=1;i<LOGN;i++) fa[x][i]=fa[ fa[x][i-1] ][i-1];
    168     for(int i=last[x];i!=0;i=e[i].next) if(e[i].y!=fa[x][0]) {
    169         fa[e[i].y][0]=x;
    170         dep[e[i].y]=dep[x]+1;
    171         dfs(e[i].y);
    172     }
    173 }
    174 
    175 bool cmp(int a,int b) {
    176     return dfn[a]<dfn[b];
    177 }
    178 
    179 int sta[N<<1],top;
    180 void work(int *pt,int &cnt,int val) {
    181     sort(pt+1,pt+cnt+1,cmp);
    182     top=0;
    183     int f; 
    184     for(int i=1,cntp=cnt;i<=cntp;i++) {
    185         if(top==0) {sta[++top]=pt[i]; continue;}
    186         f=get_lca(pt[i],sta[top]);
    187         while(top>1 && dep[f]<dep[sta[top-1]]) {
    188             top--;
    189             ans[sta[top]]=max(ans[sta[top]],val);
    190         }
    191         if(dep[f]<dep[sta[top]]) top--;
    192         if((top>0 && sta[top]!=f) || top==0) sta[++top]=f,pt[++cnt]=f;
    193         sta[++top]=pt[i];
    194     }
    195     while(top>1) {
    196         top--;
    197         ans[sta[top]]=max(ans[sta[top]],val);
    198     }
    199 }
    200 
    201 int tmp[N*4];
    202 int main() {
    203     read(n);
    204     rep(i,2,n) {
    205         int x; read(x);
    206         add(x,i);
    207     }
    208     int mx=0;
    209     rep(i,1,n) {
    210         int x; read(x);
    211         tot[x].pb(i);
    212         mx=max(mx,x);
    213     }
    214     dep[1]=1;
    215     dfs(1);
    216     clr(ans,-1);
    217     down(i,mx,1) {
    218         int cnt=0;
    219         for(int j=i;j<=mx;j+=i) {
    220             for(auto k : tot[j]) tmp[++cnt]=k;
    221         }
    222         work(tmp,cnt,i);
    223     }
    224     rep(i,1,n) printf("%d
    ",ans[i]);
    225     return 0;
    226 }
    View Code

    1007 小甜甜 暴力(

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cmath>
     5 #include <vector>
     6 #include <queue>
     7 #include <set>
     8 #include <map>
     9 #include <string>
    10 #include <string.h>
    11 #include <stdlib.h>
    12 #include <time.h>
    13 #include <climits>
    14 
    15 using namespace std;
    16 
    17 const int mod=998244353;
    18 const int maxN=1e5+7;
    19 
    20 int n;
    21 long long a[maxN];
    22 bool vis[10000];
    23 int ans;
    24 
    25 void dfs(int k){
    26     if (k>n) {
    27         a[k]=a[1];
    28         for (int i=1;i<=n;i++) 
    29             if (a[i]%n+1==a[i+1]) return;
    30         ans++;
    31         return ;
    32     }
    33 
    34     for (int i=1;i<=n;i++) if (!vis[i]) {
    35         a[k]=i;
    36         vis[i]=1;
    37         dfs(k+1);
    38         vis[i]=0;
    39     }
    40 }
    41 
    42 void baoli(){
    43     ans=0;
    44     a[1]=1;
    45     vis[1]=1;
    46     dfs(2);
    47     cout<<ans<<endl;
    48 }
    49 
    50 int main(){
    51     /*
    52     for (int i=1;i<=10;i++) {
    53         n=i;
    54         printf("%d:",i);
    55         baoli();
    56     }
    57     */
    58 
    59 
    60     a[1]=1;
    61     a[2]=0;
    62     a[3]=1;
    63     for (int i=4;i<maxN;i++) {
    64         a[i]=(i-2)*a[i-1]%mod+(i-1)*a[i-2]%mod;
    65         if (i&1) a[i]=(a[i]+1)%mod;
    66         else a[i]=(a[i]-1+mod)%mod;
    67     }
    68 
    69     int T;
    70     scanf("%d",&T);
    71     while (T--) {
    72         int n;
    73         scanf("%d",&n);
    74         printf("%lld
    ",a[n]);
    75     }
    76 
    77     return 0;
    78 }
    View Code

    1008 小甜甜 答案显然

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <algorithm>
      4 #include <cmath>
      5 #include <vector>
      6 #include <queue>
      7 #include <set>
      8 #include <map>
      9 #include <string>
     10 #include <string.h>
     11 #include <stdlib.h>
     12 #include <time.h>
     13 #include <climits>
     14 
     15 using namespace std;
     16 
     17 #define ll long long
     18 
     19 #define MAXN 9999
     20 #define MAXSIZE 10000
     21 #define DLEN 4
     22 
     23 class BigNum
     24 {
     25 private:
     26     int a[MAXSIZE];    //可以控制大数的位数
     27     int len;       //大数长度
     28 public:
     29     BigNum(){ len = 1;memset(a,0,sizeof(a)); }   //构造函数
     30     BigNum(const int);       //将一个int类型的变量转化为大数
     31     BigNum(const char*);     //将一个字符串类型的变量转化为大数
     32     BigNum(const BigNum &);  //拷贝构造函数
     33     BigNum &operator=(const BigNum &);   //重载赋值运算符,大数之间进行赋值运算
     34 
     35     friend istream& operator>>(istream&,  BigNum&);   //重载输入运算符
     36     friend ostream& operator<<(ostream&,  BigNum&);   //重载输出运算符
     37 
     38     BigNum operator+(const BigNum &) const;   //重载加法运算符,两个大数之间的相加运算
     39     BigNum operator-(const BigNum &) const;   //重载减法运算符,两个大数之间的相减运算
     40     BigNum operator*(const BigNum &) const;   //重载乘法运算符,两个大数之间的相乘运算
     41     BigNum operator/(const int   &) const;    //重载除法运算符,大数对一个整数进行相除运算
     42 
     43     BigNum operator^(const int  &) const;    //大数的n次方运算
     44     int    operator%(const int  &) const;    //大数对一个int类型的变量进行取模运算
     45     bool   operator>(const BigNum & T)const;   //大数和另一个大数的大小比较
     46     bool   operator>(const int & t)const;      //大数和一个int类型的变量的大小比较
     47 
     48     void print();       //输出大数
     49 };
     50 BigNum::BigNum(const int b)     //将一个int类型的变量转化为大数
     51 {
     52     int c,d = b;
     53     len = 0;
     54     memset(a,0,sizeof(a));
     55     while(d > MAXN)
     56     {
     57         c = d - (d / (MAXN + 1)) * (MAXN + 1);
     58         d = d / (MAXN + 1);
     59         a[len++] = c;
     60     }
     61     a[len++] = d;
     62 }
     63 BigNum::BigNum(const char*s)     //将一个字符串类型的变量转化为大数
     64 {
     65     int t,k,index,l,i;
     66     memset(a,0,sizeof(a));
     67     l=strlen(s);
     68     len=l/DLEN;
     69     if(l%DLEN)
     70         len++;
     71     index=0;
     72     for(i=l-1;i>=0;i-=DLEN)
     73     {
     74         t=0;
     75         k=i-DLEN+1;
     76         if(k<0)
     77             k=0;
     78         for(int j=k;j<=i;j++)
     79             t=t*10+s[j]-'0';
     80         a[index++]=t;
     81     }
     82 }
     83 BigNum::BigNum(const BigNum & T) : len(T.len)  //拷贝构造函数
     84 {
     85     int i;
     86     memset(a,0,sizeof(a));
     87     for(i = 0 ; i < len ; i++)
     88         a[i] = T.a[i];
     89 }
     90 BigNum & BigNum::operator=(const BigNum & n)   //重载赋值运算符,大数之间进行赋值运算
     91 {
     92     int i;
     93     len = n.len;
     94     memset(a,0,sizeof(a));
     95     for(i = 0 ; i < len ; i++)
     96         a[i] = n.a[i];
     97     return *this;
     98 }
     99 istream& operator>>(istream & in,  BigNum & b)   //重载输入运算符
    100 {
    101     char ch[MAXSIZE*4];
    102     int i = -1;
    103     in>>ch;
    104     int l=strlen(ch);
    105     int count=0,sum=0;
    106     for(i=l-1;i>=0;)
    107     {
    108         sum = 0;
    109         int t=1;
    110         for(int j=0;j<4&&i>=0;j++,i--,t*=10)
    111         {
    112             sum+=(ch[i]-'0')*t;
    113         }
    114         b.a[count]=sum;
    115         count++;
    116     }
    117     b.len =count++;
    118     return in;
    119 
    120 }
    121 /*ostream& operator<<(ostream& out,  BigNum& b)   //重载输出运算符
    122 {
    123     int i;
    124     cout << b.a[b.len - 1];
    125     for(i = b.len - 2 ; i >= 0 ; i--)
    126     {
    127         cout.width(DLEN);
    128         cout.fill('0');
    129         cout << b.a[i];
    130     }
    131     return out;
    132 }*/
    133 
    134 BigNum BigNum::operator+(const BigNum & T) const   //两个大数之间的相加运算
    135 {
    136     BigNum t(*this);
    137     int i,big;      //位数
    138     big = T.len > len ? T.len : len;
    139     for(i = 0 ; i < big ; i++)
    140     {
    141         t.a[i] +=T.a[i];
    142         if(t.a[i] > MAXN)
    143         {
    144             t.a[i + 1]++;
    145             t.a[i] -=MAXN+1;
    146         }
    147     }
    148     if(t.a[big] != 0)
    149         t.len = big + 1;
    150     else
    151         t.len = big;
    152     return t;
    153 }
    154 BigNum BigNum::operator-(const BigNum & T) const   //两个大数之间的相减运算
    155 {
    156     int i,j,big;
    157     bool flag;
    158     BigNum t1,t2;
    159     if(*this>T)
    160     {
    161         t1=*this;
    162         t2=T;
    163         flag=0;
    164     }
    165     else
    166     {
    167         t1=T;
    168         t2=*this;
    169         flag=1;
    170     }
    171     big=t1.len;
    172     for(i = 0 ; i < big ; i++)
    173     {
    174         if(t1.a[i] < t2.a[i])
    175         {
    176             j = i + 1;
    177             while(t1.a[j] == 0)
    178                 j++;
    179             t1.a[j--]--;
    180             while(j > i)
    181                 t1.a[j--] += MAXN;
    182             t1.a[i] += MAXN + 1 - t2.a[i];
    183         }
    184         else
    185             t1.a[i] -= t2.a[i];
    186     }
    187     t1.len = big;
    188     while(t1.a[len - 1] == 0 && t1.len > 1)
    189     {
    190         t1.len--;
    191         big--;
    192     }
    193     if(flag)
    194         t1.a[big-1]=0-t1.a[big-1];
    195     return t1;
    196 }
    197 
    198 BigNum BigNum::operator*(const BigNum & T) const   //两个大数之间的相乘运算
    199 {
    200     BigNum ret;
    201     int i,j,up;
    202     int temp,temp1;
    203     for(i = 0 ; i < len ; i++)
    204     {
    205         up = 0;
    206         for(j = 0 ; j < T.len ; j++)
    207         {
    208             temp = a[i] * T.a[j] + ret.a[i + j] + up;
    209             if(temp > MAXN)
    210             {
    211                 temp1 = temp - temp / (MAXN + 1) * (MAXN + 1);
    212                 up = temp / (MAXN + 1);
    213                 ret.a[i + j] = temp1;
    214             }
    215             else
    216             {
    217                 up = 0;
    218                 ret.a[i + j] = temp;
    219             }
    220         }
    221         if(up != 0)
    222             ret.a[i + j] = up;
    223     }
    224     ret.len = i + j;
    225     while(ret.a[ret.len - 1] == 0 && ret.len > 1)
    226         ret.len--;
    227     return ret;
    228 }
    229 BigNum BigNum::operator/(const int & b) const   //大数对一个整数进行相除运算
    230 {
    231     BigNum ret;
    232     int i,down = 0;
    233     for(i = len - 1 ; i >= 0 ; i--)
    234     {
    235         ret.a[i] = (a[i] + down * (MAXN + 1)) / b;
    236         down = a[i] + down * (MAXN + 1) - ret.a[i] * b;
    237     }
    238     ret.len = len;
    239     while(ret.a[ret.len - 1] == 0 && ret.len > 1)
    240         ret.len--;
    241     return ret;
    242 }
    243 int BigNum::operator %(const int & b) const    //大数对一个int类型的变量进行取模运算
    244 {
    245     int i,d=0;
    246     for (i = len-1; i>=0; i--)
    247     {
    248         d = ((d * (MAXN+1))% b + a[i])% b;
    249     }
    250     return d;
    251 }
    252 BigNum BigNum::operator^(const int & n) const    //大数的n次方运算
    253 {
    254     BigNum t,ret(1);
    255     int i;
    256     if(n<0)
    257         exit(-1);
    258     if(n==0)
    259         return 1;
    260     if(n==1)
    261         return *this;
    262     int m=n;
    263     while(m>1)
    264     {
    265         t=*this;
    266         for( i=1;i<<1<=m;i<<=1)
    267         {
    268             t=t*t;
    269         }
    270         m-=i;
    271         ret=ret*t;
    272         if(m==1)
    273             ret=ret*(*this);
    274     }
    275     return ret;
    276 }
    277 bool BigNum::operator>(const BigNum & T) const   //大数和另一个大数的大小比较
    278 {
    279     int ln;
    280     if(len > T.len)
    281         return true;
    282     else if(len == T.len)
    283     {
    284         ln = len - 1;
    285         while(a[ln] == T.a[ln] && ln >= 0)
    286             ln--;
    287         if(ln >= 0 && a[ln] > T.a[ln])
    288             return true;
    289         else
    290             return false;
    291     }
    292     else
    293         return false;
    294 }
    295 bool BigNum::operator >(const int & t) const    //大数和一个int类型的变量的大小比较
    296 {
    297     BigNum b(t);
    298     return *this>b;
    299 }
    300 
    301 void BigNum::print()    //输出大数
    302 {
    303     int i;
    304     //cout << a[len - 1];
    305     printf("%d",a[len-1]);
    306     for(i = len - 2 ; i >= 0 ; i--)
    307     {
    308         /*cout.width(DLEN);
    309         cout.fill('0');
    310         cout << a[i];*/
    311         printf("%04d",a[i]);
    312     }
    313     //cout << endl;
    314     printf("
    ");
    315 }
    316 
    317 BigNum ans[2007];
    318 
    319 int main(){
    320     ans[0]=BigNum(1);
    321     for (int i=1;i<=2000;i++) ans[i]=ans[i-1]*2;
    322 
    323     int T;
    324     scanf("%d",&T);
    325     while (T--) {
    326         int n;
    327         scanf("%d",&n);
    328         ans[n].print();
    329     }
    330     return 0;
    331 }
    View Code

    1009 BPM136 转化一下发现和2n有关,打个表发现是phi[ 2 * n ] / 2 的前缀和(咦?

      1 /* ***********************************************
      2 Author        :BPM136
      3 Created Time  :2018/8/22 16:01:27
      4 File Name     :1010.cpp
      5 ************************************************ */
      6 
      7 #include<iostream>
      8 #include<cstdio>
      9 #include<algorithm>
     10 #include<cstdlib>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<iomanip>
     14 #include<bitset>
     15 #include<queue>
     16 #include<ctime>
     17 #include<set>
     18 #include<map>
     19 #include<list>
     20 #include<vector>
     21 #include<cassert>
     22 #include<functional>
     23 #include<string>
     24 #define pb push_back
     25 #define popb pop_back
     26 #define MID ((l+r)>>1)
     27 #define LSON (k<<1)
     28 #define RSON (k<<1|1)
     29 #define get(a,i) ((a)&(1<<(i-1)))
     30 #define PAU putchar(32)
     31 #define ENT putchar(10)
     32 #define all(x) ((int) (x).size())
     33 #define clr(a,b) memset(a,b,sizeof(a))
     34 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     35 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     36 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     37 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
     38 #define Remax(a,b) if(b>a) a=b;
     39 #define Remin(a,b) if(b<a) a=b;
     40 #define SZ(x) ((int)(x).size())
     41 #define filein(x) freopen(#x".in","r",stdin)
     42 #define fileout(x) freopen(#x".out","w",stdout)
     43 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
     44 #define mkd(x) freopen(#x".in","w",stdout);
     45 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(_SIZE)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     46 #define END system("pause")
     47 #define read2(a,b) read(a),read(b)
     48 #define read3(a,b,c) read(a),read(b),read(c)
     49 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     50 #define use_cin_cout cin.sync_with_stdio(0),cout.sync_with_stdio(0),cerr.sync_with_stdio(0)
     51 using namespace std;
     52 
     53 typedef long long ll;
     54 typedef double DB;
     55 typedef long double LD;
     56 typedef unsigned int  UI;
     57 typedef unsigned long long ULL;
     58 typedef vector<int> VI;
     59 typedef vector<ll> VLL;
     60 typedef set<int> SI;
     61 typedef set<ll> SLL;
     62 typedef set<int , greater<int> > SIG;
     63 typedef set<ll , greater<ll> > SLLG;
     64 typedef map<int, int > MII;
     65 typedef map<int, int, greater<int> > MIIG;
     66 typedef map<ll, ll > MLLLL;
     67 typedef map<ll, ll, greater<ll> > MLLLLG;
     68 
     69 namespace fastIO{  
     70     #define BUF_SIZE 100000  
     71     #define OUT_SIZE 100000  
     72     //fread->read  
     73     bool IOerror=0;  
     74     inline char nc(){  
     75         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     76         if (p1==pend){  
     77             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     78             if (pend==p1){IOerror=1;return -1;}  
     79             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     80         }  
     81         return *p1++;  
     82     }  
     83     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     84     inline bool enter(char ch){return ch==10||ch==13;}
     85     inline void read(int &x){  
     86         bool sign=0; char ch=nc(); x=0;  
     87         for (;blank(ch);ch=nc());  
     88         if (IOerror)return;  
     89         if (ch==45)sign=1,ch=nc();  
     90         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     91         if (sign)x=-x;  
     92     }  
     93     inline void read(ll &x){  
     94         bool sign=0; char ch=nc(); x=0;  
     95         for (;blank(ch);ch=nc());  
     96         if (IOerror)return;  
     97         if (ch==45)sign=1,ch=nc();  
     98         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     99         if (sign)x=-x;  
    100     }  
    101     inline void read(double &x){  
    102         bool sign=0; char ch=nc(); x=0;  
    103         for (;blank(ch);ch=nc());  
    104         if (IOerror)return;  
    105         if (ch==45)sign=1,ch=nc();  
    106         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
    107         if (ch==46){  
    108             double tmp=1; ch=nc();  
    109             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
    110         }  
    111         if (sign)x=-x;  
    112     }  
    113     inline void read(char *s){  
    114         char ch=nc();  
    115         for (;blank(ch);ch=nc());  
    116         if (IOerror)return;  
    117         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    118         *s=0;  
    119     }  
    120     inline void read(char *s,bool f) {
    121         char ch=nc();
    122         for (;blank(ch);ch=nc());
    123         if(IOerror)return;
    124         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
    125         *s=0;
    126     }
    127     inline void read(char &c){  
    128         for (c=nc();blank(c);c=nc());  
    129         if (IOerror){c=-1;return;}  
    130     } 
    131 #undef OUT_SIZE  
    132 #undef BUF_SIZE  
    133 }; using namespace fastIO;
    134 
    135 const int N = 40000000;
    136 
    137 bool nop[N+5];
    138 int phi[N+5],pri[N/2];
    139 int size=0;
    140 void PHI() {
    141     nop[1]=1,phi[1]=0;
    142     for(int i=2;i<=N;i++)
    143     {
    144         if(!nop[i]) pri[++size]=i,phi[i]=i-1;
    145         for(int j=1;j<=size&&i*pri[j]<=N;j++)
    146         {
    147             nop[i*pri[j]]=1;
    148             if(i%pri[j]==0) {
    149                 phi[i*pri[j]]=phi[i]*pri[j];
    150                 break;
    151             }
    152             else phi[i*pri[j]]=phi[i]*(pri[j]-1);
    153         }
    154     }
    155 }
    156 
    157 ll ans[N/2+1];
    158 
    159 int main() {
    160     PHI();
    161     int T; read(T);
    162     rep(i,1,N/2) ans[i]=ans[i-1]+phi[i*2]/2;
    163     while(T--) {
    164         int x; read(x);
    165         printf("%lld
    ",ans[x]);
    166     }
    167     return 0;
    168 }
    View Code

    1010 小甜甜 最大曼哈顿距离 暴力一下状态每个维度做就好了

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cmath>
     5 #include <vector>
     6 #include <queue>
     7 #include <set>
     8 #include <map>
     9 #include <string>
    10 #include <string.h>
    11 #include <stdlib.h>
    12 #include <time.h>
    13 #include <climits>
    14 
    15 using namespace std;
    16 
    17 const int maxN=1e5+7;
    18 const long long INF=10000000000000000LL;
    19 
    20 int a[maxN][6];
    21 int b[maxN][6];
    22 
    23 void work(){
    24     int n,m,k;
    25     scanf("%d%d%d",&n,&m,&k);
    26 
    27     for (int i=1;i<=n;i++)
    28         for (int j=0;j<=k;j++) scanf("%d",&a[i][j]);
    29     for (int i=1;i<=m;i++) 
    30         for (int j=0;j<=k;j++) scanf("%d",&b[i][j]);
    31 
    32     long long ans=-INF;
    33 
    34     for (int sta=0;sta<(1<<k);sta++) {
    35         long long MAX=-INF;
    36         for (int i=1;i<=n;i++) {
    37             long long t=a[i][0];
    38             for (int j=0;j<k;j++) {
    39                 if (sta&(1<<j)) t+=a[i][j+1];
    40                 else t-=a[i][j+1];
    41             }
    42             MAX=max(MAX,t);
    43         }
    44 
    45         long long MIN=INF;
    46         for (int i=1;i<=m;i++) {
    47             long long t=-b[i][0];
    48             for (int j=0;j<k;j++) {
    49                 if (sta&(1<<j)) t+=b[i][j+1];
    50                 else t-=b[i][j+1];
    51             }
    52             MIN=min(MIN,t);
    53         }
    54 
    55         ans=max(ans,MAX-MIN);
    56     }
    57 
    58     printf("%lld
    ",ans);
    59 }
    60 
    61 int main(){
    62     int T;
    63     scanf("%d",&T);
    64     while (T--) work();
    65     return 0;
    66 }
    View Code

    1012 小甜甜 网络流

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <algorithm>
      4 #include <cmath>
      5 #include <vector>
      6 #include <queue>
      7 #include <set>
      8 #include <map>
      9 #include <string>
     10 #include <string.h>
     11 #include <stdlib.h>
     12 #include <time.h>
     13 #include <climits>
     14 
     15 using namespace std;
     16 
     17 const int maxN=1e4;
     18 const int maxM=3e5;
     19 const int INF=0x3f3f3f3f;
     20 
     21 struct edge{
     22     int to,cap,flow,cost,nex;
     23 }E[maxM];
     24 int head[maxN],edgenum;
     25 
     26 void init() {
     27     edgenum=0;
     28     memset(head,-1,sizeof(head));
     29     edgenum=0;
     30 }
     31 
     32 void addedge(int u,int v,int w,int c){
     33     E[edgenum]=(edge){v,w,0,c,head[u]}; 
     34     head[u]=edgenum++;
     35     E[edgenum]=(edge){u,0,0,-c,head[v]};
     36     head[v]=edgenum++;
     37 }
     38 
     39 ////////////
     40 
     41 int pre[maxN];
     42 int dist[maxN];
     43 bool vis[maxN];
     44 
     45 bool SPFA(int s,int t){
     46     queue <int> que;
     47     memset(dist,INF,sizeof(dist));
     48     memset(vis,false,sizeof(vis));
     49     memset(pre,-1,sizeof(pre));
     50     dist[s]=0;
     51     vis[s]=true;
     52     que.push(s);
     53 
     54     while (!que.empty()) {
     55         int u=que.front(); que.pop();
     56         vis[u]=false;
     57         for (int i=head[u];i!=-1;i=E[i].nex) {
     58             int v=E[i].to;
     59             if (dist[v]>dist[u]+E[i].cost && E[i].cap>E[i].flow){
     60                 dist[v]=dist[u]+E[i].cost;
     61                 pre[v]=i;
     62                 if (!vis[v]) {
     63                     que.push(v);
     64                     vis[v]=true;
     65                 }    
     66             }
     67         }
     68     }
     69 
     70     return pre[t]!=-1;
     71 }
     72 
     73 void MCMF(int s,int t,int &cost,int &flow) {
     74     flow=0;
     75     cost=0;
     76     while (SPFA(s,t)) {
     77         int Min=INF;
     78         for (int i=pre[t];i!=-1;i=pre[E[i^1].to]){
     79             Min=min(Min,E[i].cap-E[i].flow);
     80         }
     81         for (int i=pre[t];i!=-1;i=pre[E[i^1].to]){
     82             E[i].flow+=Min;
     83             E[i^1].flow-=Min;
     84             cost+=E[i].cost*Min;
     85         }
     86         flow+=Min;
     87     }
     88 }
     89 
     90 void work(){
     91     init();
     92 
     93     int n,m,k,w;
     94     scanf("%d%d%d%d",&n,&m,&k,&w);
     95 
     96     for (int i=1;i<=n;i++) {
     97         if (i<n) {
     98             addedge(i,i+1,INF,0);
     99             addedge(3*n+i,3*n+i+1,INF,0);
    100         }
    101         addedge(n+i,i,INF,w);
    102         addedge(n+i,3*n+i,INF,0);
    103         addedge(2*n+i,i,INF,0);
    104         addedge(2*n+i,3*n+i,INF,w);
    105     }
    106 
    107     for (int i=1;i<=m;i++) {
    108         int s,t,op;
    109         scanf("%d%d%d%d",&s,&t,&w,&op);
    110         if (op==0) addedge(s,n+t,1,-w);
    111         else addedge(3*n+s,2*n+t,1,-w);
    112     }    
    113 
    114     int s=0,ss=maxN-2,t=maxN-1;
    115     addedge(s,ss,k,0);
    116     addedge(ss,1,INF,0);
    117     addedge(ss,3*n+1,INF,0);
    118     addedge(n,t,INF,0);
    119     addedge(4*n,t,INF,0);
    120 
    121     int cost,flow;
    122     MCMF(s,t,cost,flow);
    123 
    124     printf("%d
    ",-cost);
    125 }
    126 
    127 int main(){
    128     int T;
    129     scanf("%d",&T);
    130     while (T--) work();
    131     return 0;
    132 }
    View Code
  • 相关阅读:
    [ARC 102D]All Your Paths are Different Lengths
    [NOI 2016] 优秀的拆分
    [TJOI 2015] 线性代数
    [LUOGU 4717] 快速沃尔什变换
    [NOI 2006] 最大获利
    Javascript继承机制的设计
    必应输入法产品分析
    你不得不知道的HTML5的新型标签
    Mobile Web
    10行代码爬取网页
  • 原文地址:https://www.cnblogs.com/MyGirlfriends/p/9524166.html
Copyright © 2011-2022 走看看