B Interesting paths

  考察范围:组合数学

  此题是机器人走方格的变种,n*m的网格,从(1,1)走到(n,m),首先可以明确,水平要走m-1格,竖直要走n-1格,则走到目的地的任意一条路径必须走n+m-2格,呢么只要确定竖直要走的,剩下的就是水平要走的,则答案为

  在Interseting paths要求左下角和右上角两个小矩阵不能走,则需要把整个网格依据两个小矩阵的水平和竖直边界分为两部分,依次运用组合数。例如

灰色区域之外为可走区域,分为两部分棕色,和黄色,则结果为

若是这种情况,则可分为两个

   

则结果为

所以需要两次分割,分别处理c到a和b到d。

因为n,m的范围比较大,可以提前预处理1到2*10^5的所有组合数和逆元。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 998244353
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) ((a,0,sizeof(a)))
typedef long long ll;
;
ll fic[],jie[];
ll t,n,m,a,b,c,d;
ll quick_pow(ll x,ll y){//求逆元
    ll ans=;
    while(y){
        ) ans=ans*x%mod;
        y>>=;
        x=x*x%mod;
    }
    return ans;
}
void get_fic(){
    fic[]=;
    jie[]=quick_pow(fic[],mod-);
    ;i<=;i++){
        fic[i]=fic[i-]*i%mod;
        jie[i]=quick_pow(fic[i],mod-);
    }
}
int main(){
    get_fic();//预处理所有值
    scanf("%lld",&t);
    while(t--){
        scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&a,&b,&c,&d);
        ll ans=;
        ;i<a;i++){//竖直处理
            ll l=fic[b+i-]*jie[b-]%mod*jie[i-]%mod;
            ll r=fic[m-b+n-i-]*jie[m-b-]%mod*jie[n-i]%mod;
            ans=(ans+(l*r)%mod)%mod;
        }
        ;i<d;i++){//水平处理
            ll l=fic[c+i-]*jie[c-]%mod*jie[i-]%mod;
            ll r=fic[m-i+n-c-]*jie[m-i]%mod*jie[n-c-]%mod;
            ans=(ans+(l*r)%mod)%mod;
        }
        printf("%lld\n",ans);
    }
    ;
}

C 三角平方数

  设三角数为m,平方数为n则根据题意有n^2=(1/2)(m+1)m,化简可得 8n^2=4m^2+4m+1-1==>

(2m+1)^2-2(2n)^2=1

令x=2m+1,y=2n则有 x^2-2y^2=1可知为佩尔方程标准形式,特解为x=3,y=2,所以可以转化为矩阵乘法求任意一个解(佩尔方程)。

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    static Scanner cin=new Scanner(System.in);
    static PrintWriter cout=new PrintWriter(System.out,true);
    public static BigInteger[][] multiply_matrix(BigInteger[][] a,BigInteger[][] b){
        BigInteger[][] c=new BigInteger[2][2];
        c[0][0]=BigInteger.valueOf(0);
        c[0][1]=BigInteger.valueOf(0);
        c[1][0]=BigInteger.valueOf(0);
        c[1][1]=BigInteger.valueOf(0);
        for(int i=0;i<2;i++)
            for(int j=0;j<2;j++)
                for(int k=0;k<2;k++)
                    c[i][j]=c[i][j].add(a[i][k].multiply(b[k][j]));
        return c;
    }
    public static BigInteger quick_pow(int y){
    BigInteger[][] ans=new BigInteger[2][2];
    BigInteger[][] pos=new BigInteger[2][2];
        ans[0][0]=BigInteger.valueOf(1);
        ans[0][1]=BigInteger.valueOf(0);
        ans[1][0]=BigInteger.valueOf(0);
        ans[1][1]=BigInteger.valueOf(1);
        pos[0][0]=BigInteger.valueOf(3);
        pos[0][1]=BigInteger.valueOf(4);
        pos[1][0]=BigInteger.valueOf(2);
        pos[1][1]=BigInteger.valueOf(3);
        while(y!=0){
            if(y%2==1) ans=multiply_matrix(ans,pos);
            y=y/2;
            pos=multiply_matrix(pos,pos);
        }
        return ans[1][0];
    }
    public static void main(String[] args){
        int n=cin.nextInt();
        BigInteger result=quick_pow(n);
        result=result.divide(BigInteger.valueOf(2));
        cout.println(result.multiply(result));
    }
}

F Star

  考察范围:最小生成树

  任意两个主星球之间都可以选择是否进行空间奇点压缩,选择不压缩就是三维排序,压缩就分别去掉x,y,z进行二维排序,最后跑最小生成树即可。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
];
ll n,k;
struct f{
  ll x,y,z;
  int id;
}edge[];
struct node{
  int u,v;
  ll dis;
  bool operator<(const node &a) const{
    return a.dis>dis;
  }
}e[];
int find(int x){
  return fa[x]=(fa[x]==x?x:find(fa[x]));
}
bool cmp_xyz(f a,f b){//自定义排序
  return a.x+a.y+a.z<b.x+b.y+b.z;
}
bool cmp_xy(f a,f b){
  return a.x+a.y<b.x+b.y;
}
bool cmp_xz(f a,f b){
  return a.x+a.z<b.x+b.z;
}
bool cmp_yz(f a,f b){
  return a.z+a.y<b.z+b.y;
}
int main(){
  scanf("%lld%lld",&n,&k);
  ;i<n;i++){
    scanf("%lld%lld%lld",&edge[i].x,&edge[i].y,&edge[i].z);
    edge[i].id=i+;
  }
  ;i<=n;i++)
    fa[i]=i;
  ;
  sort(edge,edge+n,cmp_xyz);
  ;i<n;i++)
    e[ans++]=(node){edge[i].id,edge[i-].id,edge[i].x+edge[i].y+edge[i].z-edge[i-].x-edge[i-].y-edge[i-].z};
  sort(edge,edge+n,cmp_xy);
  ;i<n;i++)
    e[ans++]=(node){edge[i].id,edge[i-].id,edge[i].x+edge[i].y-edge[i-].x-edge[i-].y};
  sort(edge,edge+n,cmp_xz);
  ;i<n;i++)
    e[ans++]=(node){edge[i].id,edge[i-].id,edge[i].x+edge[i].z-edge[i-].x-edge[i-].z};
  sort(edge,edge+n,cmp_yz);
  ;i<n;i++)
    e[ans++]=(node){edge[i].id,edge[i-].id,edge[i].z+edge[i].y-edge[i-].z-edge[i-].y};
  ;
  sort(e,e+ans);
  ll inf=;
  ;i<ans && pos>;i++){//最小生成树kruskal写法
    int x=find(e[i].u);
    int y=find(e[i].v);
    if(x!=y){
      inf+=e[i].dis;
      fa[x]=y;
      pos--;
    }
  }
  printf("%lld\n",inf*k);
  ;
}

2018年江西理工大学C语言程序设计竞赛高级组部分题解的更多相关文章

  1. 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数

    题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...

  2. 2018年江西理工大学C语言程序设计竞赛(初级组)一

     C语言竞赛初级组第一.二场答案:https://www.cnblogs.com/xingkongyihao/p/10046918.html  A: 逆序对 时间限制: 1 s      内存限制:  ...

  3. 2014江西理工大学C语言程序设计竞赛高级组题解

    1001 Beautiful Palindrome Number 枚举回文数字前半部分,然后判断该数字是否满足,复杂度为O(sqrt(n))! 1002 Recovery Sequence  本题的核 ...

  4. 2017年江西理工大学C语言程序设计竞赛(高级组)

    问题 A: 求近似值 #include <stdio.h> #include <time.h> #include <stdlib.h> using namespac ...

  5. 2017年江西理工大学C语言程序设计竞赛(初级组)

    问题 A: Petr的盒子(初) #include <iostream> #include <stdio.h> #include <algorithm> using ...

  6. 2014江西理工大学C语言程序竞赛高级组

    Beautiful Palindrome Number 题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增) 解法:打表 #include<bits/stdc++. ...

  7. 2016年江西理工大学C语言程序设计竞赛(高级组)

    问题 A: jxust 解法:争议的问题(是输入整行还是输入字符串),这里倾向输入字符串,然后判断是否含有jxust就行 #include<bits/stdc++.h> using nam ...

  8. 2016年江西理工大学C语言程序设计竞赛(初级组)

    问题 A: 木棒根数 解法:把所有的情况保存下来,加一下就好 #include<bits/stdc++.h> using namespace std; map<char,int> ...

  9. 2015年江西理工大学C语言程序设计竞赛(高级组)

    A 解法:DP+二分 dp[i]=max(dp[i],dp[j]+p[i].v)(i>j) dp[i]表示建立i点之后能够获得的最大值 int n,M; struct node { int l, ...

随机推荐

  1. IDEA - 自动添加代码

    自动添加代码Surroundwith 快捷键:Ctrl+Alt+T 有if.while.function.try.....

  2. locate-updatedb命令检索不全

    locate-updatedb命令检索不全 执行updatedb命令,用于立刻更新locate命令所必需的数据库文件,但有些文件可能会在检索过程中被过滤掉. 有时候明明存在的文件,用find命令都能搜 ...

  3. NOIP2018提高组省一冲奖班模测训练(六)

    NOIP2018提高组省一冲奖班模测训练(六) https://www.51nod.com/Contest/ContestDescription.html#!#contestId=80 20分钟AC掉 ...

  4. Swagger在 NETcore 中的使用

    请参考 https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view=asp ...

  5. 【CodeForces 271D】Good Substrings

    [链接] 我是链接,点我呀:) [题意] [题解] 字典树 我们可以两重循环(i,j) 来枚举所有的子串 即i=1,j=1,2,3... i=2,j = 2,3,4,.. 于是我们在i变化的时候(就是 ...

  6. LinkedList 注意事项

      public E getFirst() 返回此列表的第一个元素. public E getLast() 返回此列表的最后一个元素. public E removeFirst() 移除并返回此列表的 ...

  7. Hadoop Word Count程序

    Hadoop Word Count程序 pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  8. 树莓派与window 10组成的物联网核心:让人失望

    去年春天,微软公布了自己的window系统与物联网系统的方案,该方案使用树莓派和window 10组成物联网的核心.树莓派是一个与window全然不同的执行在ARM构架下的系统. 是的,也许微软决心离 ...

  9. NYOJ_94 cigarettes 递归VS迭代

    题目地址 分析: 英文题事实上看懂意思和正常的也都差点儿相同.就算有几个单词不认识也无伤大雅. 一共同拥有n支烟,每天抽k支. 每抽完k支,会得到一仅仅. a组数据.  输入n k的个数.输出一共抽了 ...

  10. [IOS]mac以太网连接

    今天玩了一下苹果一体机.感觉还是蛮不错的,只是.就是用以太网连接的时候遇到了一点问题.用这篇文章记录一下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/ ...