2019-8-15 test summary

A. Number Theory

Math, proven, this problem can be $ AC $.

Fight violence exam, get $ 20 $ points.

Correct answer:

Although the idea is still a little fuzzy, but the general idea should be about.

First, as explained in the title, if for a good number of non-$ x $, $ xp ^ c $ is non-good number, where $ p $ is a prime number, $ c> = 0 $.

$ $ Proviso that X does not contain the prime factors of $ p $.

$ Xp ^ c $ submultiple number $ val [xp ^ c] $ a $ val [x] \ times (c-1) $.

$ X $ is not prime factors of $ p $, of course, several of his covenant nor the prime factors of $ p $, so the formation of a new divisor will each take $ p $.

After that operation of some metaphysics.

Each " iteration " $ (new term $ $) $, the expansion of the number of the original sequence,

Enumeration first prime number, then the enumerator original sequence, and then enumerate the index, the number of new store to a temporary array.

Finally, delete the temporary array of new illegal number, this number will not be updated because the number of the other.

Note To sort.

Then maintains a stack, maintaining a large number of preambles $ $ k + divisor.

This will delete the current illegal number, and should be current, because the number can also be inserted after again that it is not legitimate.

Finally, all will be able to screen out illegal numbers.

Finally, $ TLE70 $.

Ugly code:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)>(y)?(x):(y))
#define _abs(x) ((x)<0?(-1*(x)):(x))
#define Maxn 1000050
#define Reg register
//#define int long long
#define int __int128
using namespace std;
bool vis[Maxn];
int T,K,m,tot,top[2],pri[Maxn],ans[Maxn];
struct Node {int x,cnt;} stack[2][Maxn],lss[Maxn];
bool comp(Node a,Node b) {return a.x<b.x;}
priority_queue<Node,vector<int>,greater<int> > q;
void print(int x)
{
    if(x>=10) print(x/10);
    putchar(x%10+48);
    return;
}
signed main()
{
    scanf("%lld%lld%lld",&T,&K,&m);
    for(Reg int i=2;i<=10000;++i)
    {
        if(vis[i]) continue;
        pri[++tot]=i;
        if(tot==300) break;
        for(Reg int j=2;j*i<=100000;++j) vis[j*i]=1;
    }
    stack[0][++top[0]]=(Node){1,1};
    for(Reg int i=1;i<=tot;++i)
    {
        int cur=i&1,pre=(i+1)&1;
        top[cur]=0;
        for(Reg int j=1;j<=top[pre];++j)
        {
            int lss=1,x=stack[pre][j].x,p=stack[pre][j].cnt;
            for(Reg int k=0;k<=60;++k)
            {
                if(lss*x>m||lss*x<0) break;
                stack[cur][++top[cur]]=(Node){lss*x,p*(k+1)};
                lss*=pri[i];
            }
        }
        sort(stack[cur]+1,stack[cur]+top[cur]+1,comp);
        int tok=0;
        while(!q.empty()) q.pop();
        for(Reg int j=1;j<=top[cur];++j)
        {
            if(stack[cur][j].x==1)
            {
                if(q.size()>=K+1&&stack[cur][j].cnt-1<q.top()) continue;
                lss[++tok]=stack[cur][j];
                q.push(stack[cur][j].cnt-1);
                while(q.size()>K+1) q.pop();
            }
            else
            {
                if(q.size()>=K+1&&stack[cur][j].cnt-2<q.top()) continue;
                lss[++tok]=stack[cur][j];
                q.push(stack[cur][j].cnt-2);
                while(q.size()>K+1) q.pop();
            }
        }
        top[cur]=0;
        for(Reg int j=1;j<=tok;++j) stack[cur][++top[cur]]=lss[j];
    }
//    for(Reg int i=1;i<=top[tot&1];++i) cout<<stack[tot&1][i].x<<endl;
    while(T--)
    {
        int x; scanf("%lld",&x);
        print(stack[tot&1][x].x); puts("");
    }
    return 0;
}
View Code

 

B. bit computing

Correct answer:

With $ dp [i] [j] $ $ I $ denotes the number, this time a total of J $ $ $ a $ 1, $ whether this exists (0/1) $.

Former record what trend, as long as the set of legal solution, so there are a like a record.

Then transferred three cases:

Symbol $ \ $ &, then the lower bound $ max (0, j + a [i + 1] -m) $, the upper bound is $ min (j, a [i + 1]) $,

Symbol $ | $, In this case the lower bound $ max (j, a [i + 1]) $, the upper bound is $ min (m, j + a [i + 1]) $,

^ Symbol, then the lower bound is $ | ja [i + 1] | $, the upper bound is $ 2mja [i + 1] $.

It is so, then the former record trend.

Finally, $ dfs $ restore the original number, a lot of trouble, a lot of details.

Ugly code:

#include<iostream>
#include<cstring>
#include<cstdio>
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)>(y)?(x):(y))
#define _abs(x) ((x)<0?(-1*(x)):(x))
#define Maxn 100050
#define Reg register
int n,m,c,opt[Maxn],dp[Maxn][35],pre[Maxn][35],A[Maxn],num[Maxn];
char s[10];
int get(int x)
{
    int s=0;
    while(x) {if(x&1) ++s; x>>=1;}
    return s;
}
void dfs(int now,int st)
{
    if(now==1) {num[1]=st; return;}
    if(opt[now-1]==1)
    {
        int nxt=pre[now][get(st)],nst=st,npt=st;
        for(Reg int i=1;i<=m;++i)
        {
            if(get(nst)==nxt) break;
            if(!(nst&(1<<(i-1)))) nst|=(1<<(i-1));
        }
        for(Reg int i=1;i<=m;++i)
        {
            if(get(npt)==A[now]) break;
            if(((st&(1<<(i-1)))&&!(nst&(1<<(i-1))))) npt|=(1<<(i-1));
            else if((!(st&(1<<(i-1)))&&!(nst&(1<<(i-1))))) npt|=(1<<(i-1));
        }
        num[now]=npt; dfs(now-1,nst);
    }
    else if(opt[now-1]==2)
    {
        int nxt=pre[now][get(st)],nst=st;
        for(Reg int i=1;i<=m;++i)
        {
            if(get(nst)==nxt) break;
            if(nst&(1<<(i-1))) nst^=(1<<(i-1));
        }
        int npt=nst^st;
        for(Reg int i=1;i<=m;++i)
        {
            if(get(npt)==A[now]) break;
            if(nst&(1<<(i-1))) npt|=(1<<(i-1));
        }
        num[now]=npt; dfs(now-1,nst);
    }
    else
    {
        int nxt=pre[now][get(st)],nst=0,npt=0;
        for(Reg int i=1;i<=m;++i)
        {
            if(!(st&(1<<(i-1)))) continue;
            if(get(nst)<nxt) nst|=(1<<(i-1));
            else npt|=(1<<(i-1));
        }
        for(Reg int i=1;i<=m;++i)
        {
            if(nxt-get(nst)==A[now]-get(npt)) break;
            if(nxt-get(nst)>A[now]-get(npt)&&(npt&(1<<(i-1)))&&!(nst&(1<<(i-1)))) nst^=(1<<(i-1)),npt^=(1<<(i-1));
            if(nxt-get(nst)<A[now]-get(npt)&&(nst&(1<<(i-1)))&&!(npt&(1<<(i-1)))) nst^=(1<<(i-1)),npt^=(1<<(i-1));
        }
        for(Reg int i=1;i<=m;++i)
            if(!(st&(1<<(i-1)))&&get(nst)<nxt&&get(npt)<A[now]) nst|=(1<<(i-1)),npt|=(1<<(i-1));
        num[now]=npt; dfs(now-1,nst);
    }
    return;
}
int main()
{
    scanf("%d%d%d",&n,&m,&c);
    for(Reg int i=1;i<=n-1;++i)
    {
        scanf("%s",s);
        if(s[0]=='A') opt[i]=1;
        else if(s[0]=='O') opt[i]=2;
        else opt[i]=3;
    }
    for(Reg int i=1;i<=n;++i) scanf("%d",&A[i]);
    dp[1][A[1]]=1;
    for(Reg int i=1;i<=n-1;++i)
    {
        for(Reg int j=0;j<=m;++j)
        {
            if(!dp[i][j]) continue;
            if(opt[i]==1) for(Reg int k=_max(0,j-(m-A[i+1]));k<=_min(j,A[i+1]);++k) dp[i+1][k]=1,pre[i+1][k]=j;
            else if(opt[i]==2) for(Reg int k=_max(j,A[i+1]);k<=_min(m,j+A[i+1]);++k) dp[i+1][k]=1,pre[i+1][k]=j;
            else
            {
                int mxx=(m-A[i+1]>j)?(A[i+1]+j):(2*m-j-A[i+1]);
                for(Reg int k=_abs(j-A[i+1]);k<=mxx;k+=2) dp[i+1][k]=1,pre[i+1][k]=j;
            }
        }
    }
    if(!dp[n][get(c)]) printf("OvO");
    else
    {
        dfs(n,c);
        for(Reg int i=1;i<=n;++i) printf("%d ",num[i]);
    }
    return 0;
}
View Code

 

C. Travel

 

to sum up:

The exam questions is fine, doing all kind of strenuous title change title.

In fact, this examination did not need to talk about the mentality, because good attitude could not think. . .

Said the examination process it,

Look minutes ago $ 40 $ $ T1 $, started playing $ k = 0 $ table in an attempt to find some rules.

Several former found very much like arithmetic sequence. . In fact, no law.

And give very little violence.

After watching $ T2 $, there is some leakage of violence points. .

Search kick, and then look at the nature of the special $ 1 $, should be able to get a number of points.

Then an hour or so yards, ah, that $ T2 $ violence could get full points.

Finally, $ T3 $, the coach thought might deliberately descending order of difficulty, it should do, then I thought for a moment, or can not do. .

Go back to see $ T1 $, still no idea, quickly code a violent, water to $ 20 $ points.

Finally, $ 20 + $ 10 + 0 = 30.

Nothing levels. . .

Guess you like

Origin www.cnblogs.com/Milk-Feng/p/11360753.html