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, ...
随机推荐
- CorelDRAW X7软件中如何将图片剪贴到文字中
将 图片剪贴到文字中是平面设计常用的一种处理方法之一,将图片剪贴到文字中是指将图片置入到该文字,且图片的外轮廓是沿着文字的形状剪贴的,这种处理手法被广泛应用于排版设计中.本教程将带大家了解如何用Cor ...
- php libevent扩展
Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能;轻量级,专注于网络,不如 ACE 那么臃肿庞大: 源代码相当精炼. ...
- 利用UNIX时间戳来计算ASP的在线时间
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!DOCTYPE html PUBLIC "-/ ...
- nyoj14-会场安排问题
会场安排问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就 ...
- 【LibreOJ 6277】数列分块入门 1 (分块)
emmm-学下分块~ 区间:数列中连续一段的元素 区间操作:将某个区间[a,b]的所有元素进行某种改动的操作 块:我们将数列划分成若干个不相交的区间,每个区间称为一个块 整块:在一个区间操作时,完整包 ...
- 判断n是否为质数
#include <iostream> #include <vector> #include <stdio.h> using namespace std; int ...
- @PostConstruct 和 @PreDestroy 指定初始化和销毁方法
通过实现 @PostConstruct 和 @PreDestroy 注解,也可以指定 bean 的初始化和销毁方法 一.Student 类 public class Student{ public S ...
- MySQL 利用binlog增量备份+还原实例
一,什么是增量备份 增量备份,就是将新增加的数据进行备份.假如你一个数据库,有10G的数据,每天会增加10M的数据,数据库每天都要备份一次,这么多数据是不是都要备份呢?还是只要备份增加的数据呢,很显然 ...
- Arduino基本函数介绍
转载自http://cnlearn.linksprite.com/?p=5248#.VwZrzvl95hE 数字 I/O (1)pinMode(pin, mode) 数字IO 口输入输出模式定义函数, ...
- ASP.NET--Razor-model-compare属性用法
学习使用model中的compare属性来判断两个密码之间是否相同 [Required] [StringLength(100, ErrorMessage = "The {0} must be ...