2017.11.7 Noip2017 考前模拟赛

----------------------------------T1----------------------------------

——>数学老师的报复

题目描述

11 班数学大佬 YXN 又在上数学课的时候把班主任 MP6 的错误当众挑出来了,MP6 再一次感到很难堪,于是决定报复 YXN

MP6 对 YXN 说:给你一个函数 f(x),定义如下:
f ( 1 ) = 1
f ( 2 ) = 1
f ( n ) = ( A * f ( n - 1 ) + B * f ( n - 2 ) ) mod 7。

YXN 说这还不简单,可以秒杀! MP6 微微笑了笑说:n 等于 100 你算得出来,那 n 等于 2147483648 呢?

YXN 哑口无言,决定向信息组的你求助。由于这是你唯一一次可以在数学题上秒杀 YXN,

你决定好好把握这一次机会。

输入输出格式

输入格式:

仅一行包含 3 个整数 A,B 和 n。

输出格式:

一个整数,即 f ( n ) 的值。

输入输出样例

暂无测试点

说明

20%的数据, n≤1,000

50%的数据, n≤100,000,000

100%的数据,n≤2147,483,648

思路

  ①骗分

    找出0~6 0~6的规律,打个表,然后按照规律进行输出即可(竟然95....)

    表:

//无限不会打...用‘&’代替好啦
0 0  -> {
  1 1 0
      0
      .
}
0 1  -> & (all 1)
0 2  -> 6
0 3  -> 12
0 4  -> 6
0 5  -> 12
0 6  -> 6
0 7  -> {
  1 1 0
      0
      .
}
------------------------------
1 0  -> & (all 1)
1 1  -> 16
1 2  -> 6
1 3  -> 24
1 4  -> 48
1 5  -> 21
1 6  -> 6
//循环
1 7  -> & (all 1)
------------------------------
2 0  -> {
  1 1 2 4 1
      2 4 1 
      .....
}
2 1  -> 6
2 2  -> 48
2 3  -> 6
2 4  -> 48
2 5  -> 24
2 6  -> & (all 1)
2 7  -> {
  1 1 2 4 1
      2 4 1 
      .....
}
------------------------------
3 0  -> {
  1 1 3 2 6 4 5
    1 3 2 6 4 5
    ...........
}
3 1  -> 16
3 2  -> 48
3 3  -> 42
3 4  -> 6
3 5  -> & (all 1)
3 6  -> 8
------------------------------
4 0  -> {
  1 1 4 2
    1 4 2
    .....
}
4 1  -> 16
4 2  -> 48
4 3  -> 21
4 4  -> & (all 1)
4 5  -> 6
4 6  -> 8
4 7  -> {
  1 1 4 2
    1 4 2
    .....
}
------------------------------
5 0  -> {
  1 1 5 4 6 2 3
    1 5 4 6 2 3
    ...........
}
5 1  -> 6
5 2  -> 48
5 3  -> & (all 1)
5 4  -> 48
5 5  -> 24
5 6  -> 14
5 7  -> {
  1 1 5 4 6 2 3
    1 5 4 6 2 3
    ...........
}
------------------------------
6 0  -> {
  1 1 6
    1 6
    ...
}
6 1  -> 32
6 2  -> & (all 1)
6 3  -> 24
6 4  -> 48
6 5  -> 42
6 6  -> 3 -> {
	1 1 5
	.....
}
6 7  -> {
  1 1 6
    1 6
    ...
}
------------------------------

 

  ②正解骗分

    mod 7 ?

    这显然会是一个很小的数,如果一旦连续 2 次 mod 7 为 1,

    那么又会重新开始,你就发现这是一个周期函数!

    所以可以先模拟出周期函数,遇到第二个周期就 break 掉,变成一个循环结,询问时模上个周期就行

  ③正解

    矩阵快速幂的板子题:

    转置矩阵为  A 1

           B 0

代码酱=u=

令人窒息的打表操作(95——那个点自生自灭吧...不会...我记得应该是第10个来着)

#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
#define INF 2147483648
using namespace std;

inline LL read() {
    LL x=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*f;
}

const int mod = 7;
const int M = 51;
const int x[mod][mod][M] = {
    {{0,1,1,0},{0,1,1,1},{0,1,1,2,2,4,4,1,1},{0,1,1,3,3,2,2,6,6,4,4,5,5,1,1},{0,1,1,4,4,2,2,1,1},{0,1,1,5,5,4,4,6,6,2,2,3,3,1,1},{0,1,1,6,6,1,1}},
    {{0,1,1,1},{0,1,1,2,3,5,1,6,0,6,6,5,4,2,6,1,0,1,1},{0,1,1,3,5,4,0,1,1},{0,1,1,4,0,5,5,6,0,4,4,2,0,6,6,3,0,2,2,1,0,3,3,5,0,1,1},{0,1,1,5,2,1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,1},{0,1,1,3,4,6,6,4,3,1,1}},
    {{0,1,1,5,4,6,2,3,1},{0,1,1,6,3,0,3,1,1},{0,1,1,0,2,3,5,3,4,5,5,0,3,1,4,1,6,4,4,0,1,5,6,5,2,6,6,0,5,4,2,4,3,2,2,0,4,6,3,6,1,3,3,0,6,2,1,2,5,1,1},{0,1,1,1},{0,1,1,2,0,1,5,1,4,3,3,6,0,3,1,3,5,2,2,4,0,2,3,2,1,6,6,5,0,6,2,6,3,4,4,1,0,4,6,4,2,5,5,3,0,5,4,5,6,1,1},{0,1,1,3,6,3,3,2,4,2,2,6,5,6,6,4,1,4,4,5,3,5,5,1,2,1,1},{0,1,1,4,5,0,2,3,6,6,3,2,0,5,4,1,1}},
    {{0,1,1,6},{0,1,1,0,1,6,2,4,5,6,6,0,6,1,5,3,2,1,1,0,1,6,2,4,5,6,6,0,6,1,5,3,2,1,1},{0,1,1,1},{0,1,1,2,1,5,5,3,5,4,4,1,4,6,6,5,6,2,2,4,2,3,3,6,3,1,1},{0,1,1,3,1,4,0,2,5,3,3,2,3,5,0,6,1,2,2,6,2,1,0,4,3,6,6,4,6,3,0,5,2,4,4,5,4,2,0,1,6,5,5,1,5,6,0,3,4,1,1},{0,1,1,4,1,5,0,4,3,3,5,3,1,0,5,2,2,1,2,3,0,1,6,6,3,6,2,0,3,4,4,2,4,6,0,2,5,5,6,5,4,0,6,1,1},{0,1,1,5,1}}
};
const int Mod[mod][mod] = {
    {1, 1, 6,12, 6,12, 4},
    {1,16, 6,24,48,22, 6},
    {3, 6,48, 6,48,24, 1},
    {6,16,48,42, 6, 1, 8},
    {3,16,48,21, 1, 6, 8},
    {6, 6,48, 1,48,24,14},
    {1,32, 1,24,48,42, 2}
};

int main() {
    freopen("attack.in","r",stdin);
    freopen("attack.out","w",stdout);
    LL A,B,n,p,q;
    A=read()%mod,B=read()%mod,n=read();
    p=Mod[A][B];
    q=(n+p)%p;
    if(B==0) q+=3;
    if(A!=0 && B!=0 && p==1 && q==0) {
        printf("1");
        return 0;
    }
    printf("%d",x[A][B][q]);
    fclose(stdin);fclose(stdout);
    return 0;
}
View Code

 ——>表的生成:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;

const int Mod[7][7] = {
    {1, 1, 6,12, 6,12, 4},
    {1,16, 6,24,48,22, 6},
    {3, 6,48, 6,48,24, 1},
    {6,16,48,42, 6, 1, 8},
    {3,16,48,21, 1, 6, 8},
    {6, 6,48, 1,48,24,14},
    {1,32, 1,24,48,42, 2}
};

int main() {
    LL A,B,p,f[55],now=0;
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    while(cin>>A>>B) {
        A%=7,B%=7;
        memset(f,0,sizeof(f));
        f[1]=f[2]=1,f[3]=(A+B)%7;
        p=Mod[A][B];
        for(int i=4; i<=p+2; i++) f[i]=(A*f[i-1]+B*f[i-2])%7;
        now++;
        now%=7;
        printf("{");
        if(now==1) printf("{");
        for(int i=0; i<=p+1; i++) printf("%d,",f[i]);
        printf("%d}",f[p+2]);
        if(!now) printf("},\n");
        else printf(",");
        //这样的表最后要删除最后一个",",懒得弄了.... 
    }
    return 0;
}
View Code

②正解骗分(AC)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 10000000
using namespace std;

int a,b,n,T;
int f[maxn];

inline int read() {
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}

int main() {
    bool flag=false;
    a=read();
    b=read();
    n=read();
    f[1]=f[2]=1;
    f[3]=(a+b)%7;
    for(int i=4; i<=n; i++) {
        f[i]=(a*f[i-1]+b*f[i-2])%7;
        if(f[i-1]==1&&f[i]==1)    {
            flag=true;
            T=i-2;
            break;
        }
    }
    if(!flag)    printf("%d",f[n]);
    else {
        int pos=n%T;
        if(pos==0)    pos=T;
        printf("%d",f[pos]);
    }
    return 0;
}
View Code

③正解:矩阵快速幂(不会不学了)

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,aa,bb;
struct matrix {
    ll a[2][2];
    matrix() {
        memset(a,0,sizeof(a));
    }
    matrix(ll b[2][2])    {
        for(int i=0; i<2; i++)for(int j=0; j<2; j++)a[i][j]=b[i][j];
    }
    matrix operator * (matrix b) {
        matrix ans;
        for(int i=0; i<2; i++)
            for(int j=0; j<2; j++)
                for(int k=0; k<2; k++)
                    ans.a[i][j]=(ans.a[i][j]+a[i][k]*b.a[k][j])%7;
        ans.a[0][0]%=7;
        return ans;
    }
} S,T;

inline ll read() {
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}

int main() {
    freopen("attack.in","r",stdin);
    freopen("attack.out","w",stdout);
    while(scanf("%lld%lld%lld",&aa,&bb,&n)!=EOF) {
        n-=2;
        if(n==-1)    {
            printf("1");
            return 0;
        }
        ll temp[2][2]= {{aa,1},{bb,0}};
        T=temp;
        ll temp2[2][2]= {{1,1},{0,0}};
        S=temp2;
        while(n) {
            if(n&1)    S=S*T;
            T=T*T;
            n>>=1;
        }
        S.a[0][0]%=7;
        printf("%lld",S.a[0][0]);
    }
    return 0;
}
View Code

----------------------------------T2----------------------------------

——>物理和生物老师的战争

题目描述

物。万物也。牛为大物。牛为物之大者。故物从牛。与半同意。天地之数起於牵牛。戴先生原象曰。牵牛为纪首。

命曰星纪。自周而上。日月之行不起於;牵牛也。按许说物从牛之故。又广其义如此。故从牛。勿声。文弗切。十五部。

总之,物理老师和生物老师因为“物”而吵了起来,物理老师认为,物理是万物之源, 而生物老师认为生物才是万物之源。

所以物理学科带头人和生物学科带头人号召了所有物理、生物老师,进行战斗。

战斗开始前他们需要排队,有 n 个物理老师和 m 个生物老师站在一起排成一列过安检进入打斗场。

物理老师是一个神奇的物种,他们十分严谨,在开始之前就分析过:

如果在任意某一个人往前数(包括这个人) ,生物老师的数量超过了物理老师,根据牛顿三大定律以及开普勒三大定律,这样风水是不太好的。

这时候,物理老师就会引爆核弹。为了构建社会主义和谐社会,你决定避免这一场核战的发生。

所以,请你计算不会引发核弹爆炸的排队方案的概率。

(排队方案不同定义为当且仅当某一位老师不一样,注意不是老师所教的科目不一样。eg:物 A 物 B,物 B 物 A,是不同的方案)

输入输出格式

输入格式:

第一行,Test , 表示测试数据的组数。

每个数据 有两个数 N,M

输出格式:

对于每组数据,输出一个实数(保留到小数点后 6 位,)

输入输出样例

暂无测试点

说明

30%的数据:(Test<=10),(0<=N,M<=1000).

100%的数据:(Test<=9008 ),( 0<=N,M<=20000 ).

思路

  30 分做法:
    暴力枚举每个位置上的老师,判断是否可行
  100 分做法:
    组合数学题
    可以将原问题转化一下,看成是在一个二维平面上行走,物理老师看成移动(1,0),生物老师看成移动(0,1),

    那么到达(N,M)点且路线又不走到 y=x 这条直线上方的路线总数就是答案,这个组合问题很经典,

    方案数为C[m][m+n]-C[m-1][m+n]
    所以可以知道答案就是1-{m/(n+1)}

代码酱=u=

①std

#include <iostream>
#include <cstdio>
using namespace std;

inline int read() {
    int x=0,f=1; char c=getchar();
    while(c<'0' || c>'9') { if(c=='-') f=-1; c=getchar(); }
    while(c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*f;
}

int T;
double n,m;

int main() {
    T=read();
    while(T--) {
        n=read(),m=read();
        if(n<m) { puts("0.000000"); continue; }
        n++;
        double N=n-m;
        printf("%.6lf\n",N/n);
    }
    return 0;
}
View Code std

②另一种方法

#include <iostream>
#include <cstdio>
using namespace std;

inline int read() {
    int x=0,f=1; char c=getchar();
    while(c<'0' || c>'9') { if(c=='-') f=-1; c=getchar(); }
    while(c>='0' && c<='9') x=x*10+c-48,c=getchar();
    return x*f;
}

int T;
double n,m;

int main() {
    T=read();
    while(T--) {
        n=read(),m=read();
        if(n<m) { puts("0.000000"); continue; }
        n++;
        double d=m/n;
        printf("%.6lf\n",1.0-d);
    }
    return 0;
}
View Code AC

----------------------------------T3----------------------------------

——>化学竞赛的的大奖

题目描述

XYX 在 CChO(全国化学奥林匹克竞赛)比赛中获得了大奖,奖品是一张特殊的机票。

使用这张机票,可以在任意一个国家内的任意城市之间的免费飞行,只有跨国飞行时才会有额外的费用。XYX 获得了一张地图,地图上有城市之间的飞机航班和费用。

已知从每个城市出发能到达所有城市,两个城市之间可能有不止一个航班。

一个国家内的每两个城市之间一定有不止一条飞行路线, 而两个国家的城市之间只 有一条飞行路线。

XYX想知道, 从每个城市出发到额外费用最大的城市, 以便估算出出行的费用, 请你帮助他。

当然,你不能通过乘坐多次一个航班增加额外费用, 也就是必须沿费用最少的路线飞行。

输入输出格式

输入格式:

第一行,两个整数 N,M,表示地图上有 N 个城市,M 条航线。

接下来 M 行,每行三个整数 a,b,c,表示城市 a,b 之间有一条费用为 c 的航线。

输出格式:

共 N 行,第 i 行为从城市 i 出发到达每个城市额外费用的最大值。

输入输出样例

暂无测试点

说明

对于 40%的数据 1<=N<=1000,1<=M<=1000

对于 100%的数据 1<=N<=20000,1<=M<=200000

思路

什么求 SCC(强联通分量),缩点 [NOIP2015 Day1 T2],什么两次 dfs/树形 DP 求出树的直径的两个端点 A,B

不会.弃疗.

代码酱=u=

#include<bits/stdc++.h>
#define maxn 20005
#define maxm 200005
using namespace std;

int n,m,id,dfn[maxn],low[maxn],head[maxn],head2[maxn],cnt;
int dis[maxn],dis1[maxn],mx=0,root;
int belong[maxn],belnum;
bool vis[maxn];
stack<int> stk;
struct Edge {
    int u,v,val,next;
} edge[maxm<<1],e[maxm<<1];

inline int read() {
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}

namespace Tarjan {
    inline void add(int u,int v,int val) {
        edge[++cnt].v=v;
        edge[cnt].u=u;
        edge[cnt].val=val;
        edge[cnt].next=head[u];
        head[u]=cnt;
    }
    inline void tarjan(int u,int fa) {
        dfn[u]=low[u]=++id;
        vis[u]=1;
        stk.push(u);
        for(int i=head[u]; i!=-1; i=edge[i].next) {
            int v=edge[i].v;
            if(!dfn[v]) {
                tarjan(v,u);
                low[u]=min(low[u],low[v]);
            } else if(vis[v]&&v!=fa) {
                low[u]=min(low[u],dfn[v]);
            }
        }
        if(dfn[u]==low[u]) {
            belnum++;
            int temp;
            do {
                temp=stk.top();
                belong[temp]=belnum;
                vis[temp]=0;
                stk.pop();
            } while(temp!=u);
        }
    }
    inline void solve1() {
        memset(head,-1,sizeof(head));
        for(int i=1,u,v,val; i<=m; i++) {
            u=read();
            v=read();
            val=read();
            add(u,v,val);
            add(v,u,val);
        }
        for(int i=1; i<=n; i++) {
            if(!dfn[i])    tarjan(i,0);
        }
    }
}

namespace LP {
    inline void Add(int u,int v,int val) {
        e[++cnt].v=v;
        e[cnt].val=val;
        e[cnt].next=head2[u];
        head2[u]=cnt;
    }
    void dfs1(int u,int fa) {
        for(int i=head2[u]; i!=-1; i=e[i].next) {
            int v=e[i].v;
            if(v==fa)    continue;
            dis[v]=dis[u]+e[i].val;
            if(dis[v]>mx)    mx=dis[v],root=v;
            dfs1(v,u);
        }
    }
    void dfs2(int u,int fa) {
        for(int i=head2[u]; i!=-1; i=e[i].next) {
            int v=e[i].v;
            if(v==fa)    continue;
            dis1[v]=dis1[u]+e[i].val;
            dfs2(v,u);
        }
    }
    inline void solve2() {
        cnt=0;
        memset(head2,-1,sizeof(head2));
        for(int i=1; i<=n; i++)
            for(int j=head[i]; j!=-1; j=edge[j].next) {
                if(belong[i]!=belong[edge[j].v])
                    Add(belong[i],belong[edge[j].v],edge[j].val);
            }
        dfs1(1,-1);
        mx=0;
        memset(dis,0,sizeof(dis));
        dfs1(root,-1);
        mx=0;
        dfs2(root,-1);
        for(int i=1; i<=n; i++)
            printf("%d\n",max(dis[belong[i]],dis1[belong[i]]));
    }
}

int main() {
    freopen("prize.in","r",stdin);
    freopen("prize.out","w",stdout);
    n=read();
    m=read();
    Tarjan::solve1();
    LP::solve2();
    return 0;
}
View Code

----------------------------------------------------------------------

小结=u=

果然还是好好的做好第一题比较重要qaq

转载于:https://www.cnblogs.com/zxqxwnngztxx/p/7799435.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值