2018年江西理工大学C语言程序设计竞赛高级组部分题解
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语言程序设计竞赛高级组部分题解的更多相关文章
- 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数
题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...
- 2018年江西理工大学C语言程序设计竞赛(初级组)一
C语言竞赛初级组第一.二场答案:https://www.cnblogs.com/xingkongyihao/p/10046918.html A: 逆序对 时间限制: 1 s 内存限制: ...
- 2014江西理工大学C语言程序设计竞赛高级组题解
1001 Beautiful Palindrome Number 枚举回文数字前半部分,然后判断该数字是否满足,复杂度为O(sqrt(n))! 1002 Recovery Sequence 本题的核 ...
- 2017年江西理工大学C语言程序设计竞赛(高级组)
问题 A: 求近似值 #include <stdio.h> #include <time.h> #include <stdlib.h> using namespac ...
- 2017年江西理工大学C语言程序设计竞赛(初级组)
问题 A: Petr的盒子(初) #include <iostream> #include <stdio.h> #include <algorithm> using ...
- 2014江西理工大学C语言程序竞赛高级组
Beautiful Palindrome Number 题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增) 解法:打表 #include<bits/stdc++. ...
- 2016年江西理工大学C语言程序设计竞赛(高级组)
问题 A: jxust 解法:争议的问题(是输入整行还是输入字符串),这里倾向输入字符串,然后判断是否含有jxust就行 #include<bits/stdc++.h> using nam ...
- 2016年江西理工大学C语言程序设计竞赛(初级组)
问题 A: 木棒根数 解法:把所有的情况保存下来,加一下就好 #include<bits/stdc++.h> using namespace std; map<char,int> ...
- 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, ...
随机推荐
- 基于libVLC的视频播放器
本文来自于:http://blog.csdn.net/leixiaohua1020/article/details/42363079 最简单的基于libVLC的例子:最简单的基于libVLC的视频播放 ...
- 面试题-mysql
Sql :UPDATE test SET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' END;
- WebStorm 配置 svn
1.下载 SlikSVN. 2.安装.路径 D:\Program Files\slik\bin. 3.在WebStorm中配置 file->settings->Version Co ...
- 关闭浏览器 清除session
捕获关闭浏览器的事件 关于关闭IE清空session的总结 Session过期会清楚session 还可以手动清除session实现关闭浏览器时清除session的方法
- Linux搭建Jenkins
1.添加存储库 yum的repo中默认没有Jenkins,需要先将Jenkins存储库添加到yum repos,执行下面的命令: 使用wget -O下载并以不同的文件名保存 [root@besttes ...
- 【图像处理】使用OpenCV实现人脸和行人检测
OpenCV全称是Open source Computer Vision Library(开放源代码计算机视觉库),是一个用于图像处理.分析.机器视觉方面的开源函数库,提供了很多图像处理的工具和可 ...
- JavaScript进阶【一】JavaScript模块化开发的基础知识
//模块化的最初写法 //1.最初写法 //下面的m1和m2就组成了一个模块 //缺点:"污染"了全局变量,无法保证不与其他模块发生变量名冲突,而且模块成员之间看不出直接关系. f ...
- nyoj2-吝啬的国度
吝啬的国度 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市,他有 ...
- MySQL数据库中字段类型为tinyint,读取出来为true/false的问题
由于MySQL中没有boolean类型,所以会用到tinyint类型来表示. 数据库一个表中有一个tinyint类型的字段,值为0或者1,如果取出来的话,0会变成false,1会变成true.
- 酒店管理系统(功能结构图、E-R图、用例图)
功能结构图 用例图 状态图 流程图 数据字典 er图