UOJ Logo heqingyu的博客

博客

普及转提高第7场训练博客

2018-01-13 22:06:01 By heqingyu

这次总算是进前三了。。。。

然而原因竟是XMR和LKY爸爸都没交。。。

T1:

这是一道结论题。。。

每个数都可以被分解成若干个质数之积,因此只需要从1~n,寻找能否整除n,能的话直接除。。。

code:

#include<bits/stdc++.h>
using namespace std;
long long n,ans,p[1000010];
int main(){
    freopen("math.in","r",stdin);
    freopen("math.out","w",stdout);    
    scanf("%lld",&n);
    for(long long i=2;i<=n;i++)
        if(n%i==0){n/=i;break;}
    for(long long i=2;i<=n;i++)
        if(n%i==0){n/=i;ans=i;break;}
    printf("%lld",ans);
    return 0;
}

T2:

这道题目是一道纯暴力模拟题。。。

code:

#include<bits/stdc++.h>
using namespace std;
int n,ans;
struct node {
    char mp[15][15];
}a,b;
node solve2(node a){
    node f;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            f.mp[j][n-i+1]=a.mp[i][j];
    return f;
}
node solve1(node a){
    node f;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            f.mp[i][n-j+1]=a.mp[i][j];
    return f;
}
bool check(node a,node b){
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(a.mp[i][j]!=b.mp[i][j])return false;
    return true;
}
int main(){
    freopen("transform.in","r",stdin);
    freopen("transform.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%s",b.mp[i]+1);
    for(int i=1;i<=n;i++) scanf("%s",a.mp[i]+1);
    if(check(a,solve2(b))) ans=1;
    else if(check(a,solve2(solve2(b)))) ans=2;
    else if(check(a,solve2(solve2(solve2(b))))) ans=3;
    else if(check(a,solve1(b))) ans=4;
    else if(check(a,solve2(solve1(b)))||check(a,solve2(solve2(solve1(b))))||check(a, solve2(solve2(solve2(b))))) ans=5;
    else if(check(a,b)) ans=6;
    else ans=7;
    printf("%d",ans);
    return 0;
}

T3:

这道题第一眼看到就明白是DFS。。。。

但是为了有趣(细节调不好),所以打表

code:

#include<bits/stdc++.h>
using namespace std;
int f4[110]={0,2333,2339,2393,2399,2939,3119,3137,3733,3739,3793,3797,5939,7193,7331,7333,7393,};
int f1[110]={0,2,3,5,7};
int f2[110]={0,23,29,31,37,53,59,71,73,79};
int f3[110]={0,233,239,293,311,313,317,373,379,593,599,719,733,739,797};
int f5[110]={0,23333,23339,23399,23993,29399,31193,31379,37337,37339,37397,59393,59399,71933,73331,73939};
int f6[110]={0,233993,239933,293999,373379,373393,593933,593993,719333,739391,739393,739397,739399,};
int f7[110]={0,2339933,2399333,2939999,3733799,5939333,7393913,7393931,7393933};
int f8[110]={0,23399339,29399999,37337999,59393339,73939133};
void work(int x){
    int i=0;
    if(x==1)while(f1[++i]) printf("%d\n",f1[i]); 
    if(x==2)while(f2[++i]) printf("%d\n",f2[i]);
    if(x==3)while(f3[++i]) printf("%d\n",f3[i]);
    if(x==4)while(f4[++i]) printf("%d\n",f4[i]);
    if(x==5)while(f5[++i]) printf("%d\n",f5[i]);
    if(x==6)while(f6[++i]) printf("%d\n",f6[i]);
    if(x==7)while(f7[++i]) printf("%d\n",f7[i]);
    if(x==8)while(f8[++i]) printf("%d\n",f8[i]);
    return ;
}
int main(){
    freopen("sprime.in","r",stdin);
    freopen("sprime.out","w",stdout);
    int n;
    scanf("%d",&n);
    work(n);
    return 0;
}

T4:

这是一道并查集的高级操作。。。

XRY大佬当场怒A(就当他A了。。。)好强!!

维护一个并查集,fa[i]是当前集合的爸爸(就像ZJH和XRY一样。。。)

然后再维护一个数组s[i]表示i这条边与他的爸爸是平行还是垂直

然后判断ORZK的话就可以把a,b还有p(操作序号)xor起来。。。

code:

#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,p,fa[100010],s[100010],ans[100010];
int getfa(int x){
    if(fa[x]==x) return x;
    int t=getfa(fa[x]);    
    s[x]^=s[fa[x]];
    return fa[x]=t;
}
bool check(int x,int y,int w){
    int fx=getfa(x),fy=getfa(y);
    if(fx==fy) return s[x]^s[y]^w;
    fa[fx]=fy;
    s[fx]=s[x]^s[y]^w;
    return 0;
}
int main(){
    freopen("imo.in","r",stdin);
    freopen("imo.out","w",stdout);
    scanf("%d%d",&n,&m);int cnt=0;
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&p,&a,&b);
        if(p==3){
            int fx=getfa(a),fy=getfa(b);    
            if(fx!=fy) ans[++cnt]=2;
            else ans[++cnt]=s[a]^s[b];
        }
        else if(check(a,b,p-1)){puts("ORZKsister");return 0;}
    }
    for(int i=1;i<=cnt;i++){
        if(ans[i]==1) puts("J"); 
        else if(!ans[i]) puts("Z");
        else puts("K"); 
    }
    //cout<<cnt<<endl;
    return 0;
}

评论

zhoushouchen
@heqingyu
  • 2018-02-05 14:38:00