"科林明伦杯"哈尔滨理工大学第九届程序设计竞赛

A氵题

B错排公式

C

不太懂卡塔兰数是啥东西,于是乎写的是一个n^2的dp,暴力打表写文件里,然后复制到代码里,然后切掉了

打表代码

#include
using namespace std;
typedef long long ll;
const int maxn = 2e3+7,mod = 998244353;
ll dp[maxn][maxn];
ll ans[maxn];
void init(){
    for(int n=1;n<=1e3;n++){
        memset(dp,0,sizeof dp);
        dp[0][0] = 1;
        for(int i=1;i<=2*n;i++){// i-th day j-th remain第i天剩j个坑没填
            dp[i][0] = dp[i-1][1];//只能从前一天剩余一个坑转移过来
            for(int j=min(i,n);j;j--){
                dp[i][j] = (dp[i-1][j-1]+dp[i-1][j+1])%mod;
                //前一天填一个坑加上前一天挖一个坑
            }
        }
        ans[n] = dp[2*n][0];
    }
}
int main() {
    init();
    FILE *p = fopen("ans.txt","w");
    for(int i=1;i<=1e3;i++)
        fprintf(p,"%lld,",ans[i]);
    /*int n,t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        printf("%lld\n",ans[n]);
    }*/
	return 0;
}
1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700,769018837,574654302,508402548,642327517,661800571,172443248,496402342,655221305,840507789,812999877,893261956,51209616,195236661,563950096,335951841,59801129,395611720,493069698,475867917,217712649,788281481,992584106,263380291,877480516,395532571,797346749,741681113,387050495,376795771,564662142,873206565,512803529,725042030,124711617,152241504,374559084,887679661,830319856,997940027,489476123,12292609,768006434,840206673,428680286,489117198,621280656,522903345,554869270,408910345,81016465,744940600,892201408,166974338,284959769,900897613,217347391,248030030,570902521,12841718,707463784,381008905,423624359,397434523,153844159,105265591,319679442,815329837,175934426,555617945,917580549,814065971,767311772,588697026,159311791,117336529,966311482,435776769,512083881,224218081,732034205,987550497,639828769,936231176,65693878,220591467,955324443,19097780,653742178,27580800,255336272,952967963,711667857,580322362,656182019,120850886,190645553,942043440,725130781,444178466,663799270,126396234,944814834,279849451,180544528,520233502,690364525,256740439,95189851,641456036,307350424,508766442,876355789,334731513,663332878,299359606,274622031,924891742,868348445,354102584,919957191,802535938,160020986,632411,819248489,289719058,155527948,424276110,355585355,908803621,818273355,644927168,339434359,201611623,289631268,84175322,488009756,935025065,531602919,261367571,903763763,499084471,867889151,259819437,368300406,71924094,484729825,321802572,343156788,932552544,412936948,263119555,535367249,21837256,444343974,763809337,171218623,645006436,747785767,655393697,591964010,684383318,905873340,17501282,85795977,329535731,940533030,93030671,774841330,525927355,486653319,239483794,767487767,768722145,635549483,268773584,83937632,536904346,752978348,569109556,157448067,794770366,577800661,880684382,344615673,458162968,46749812,146870832,756833916,49164871,243010940,679887918,585454263,790211464,186032658,972149425,170285341,482308147,954454161,494593437,515317744,177777431,295241395,714333272,447698630,370565023,567303478,443178489,6376653,209225923,992710179,160295773,209200557,822786314,797910451,841945738,801825327,403675307,795777314,126371544,552434724,898210369,78695203,106580858,152563710,33740120,928655207,697237642,161220698,109658684,796803570,732374773,700741686,647187376,490108624,46690722,808098997,460485413,522209125,451643155,104104937,774921054,637892385,113742201,767409215,488522744,598225427,848266187,682107702,16410070,388126519,723102352,541023674,904354909,207900791,331571643,542236676,30464459,643744639,306057975,477017101,122397724,753412747,979892982,494889389,134300906,944181813,112978317,167816883,730161619,781195795,423687421,975922517,75266286,745837883,258609964,24167881,278293780,300890920,963018545,787937186,380835586,431279497,156379539,503818242,573636628,404598714,729657707,742049587,937807812,30794758,624925324,64254227,236584243,450652832,77274170,925585581,683716853,133418960,342810510,203826623,393469920,391022406,43936274,134751925,296194209,850655879,722940932,286726721,916448218,399475573,882793104,981861192,49020321,950626194,993929977,155650134,298956813,44152755,725156976,255255062,910819286,635445342,744301204,551518589,937041912,546169723,40234269,459427010,5409274,78750080,484777922,975240548,594669883,980078975,722857979,736504184,656709321,65663318,997688270,445465577,593182064,73267268,21611751,11840205,261075156,840360107,483848266,442356262,471005348,699570645,250857943,961705172,868777686,182719327,12626499,777025861,987709371,209574723,74405183,817953056,558383505,259692640,616578800,989262867,244970616,462681930,322894116,125821106,480756379,783924493,835354386,193447744,628223705,537295656,408007722,208073601,874516517,417196522,393371963,696923274,650978775,169511428,586120674,309543230,749278978,43043242,540346351,215795436,155365209,743657097,27446358,262400313,420665706,985273286,338921074,949081083,178397638,495575258,260499843,861968152,783080925,614882449,302906177,881659796,331081816,866332791,669292929,89164037,201471308,977585695,89444517,569615222,911828085,367905373,26671268,85663861,712383889,898089324,161409658,859453565,408674008,739543935,892927720,154770059,63907418,245795016,827674714,793928806,250565254,772140046,509449515,12397734,314446989,962743946,808338819,640424207,701264223,56684892,474468273,541105003,43688208,260799784,495315206,676908790,779843316,913173193,993231271,227969992,13096959,765251965,863596806,830147589,987850557,372205484,157330005,70417423,855401726,993714581,796404921,230927199,708695281,312689475,662830422,931811736,250715160,516073601,406506541,751909850,993723570,73835315,763000830,478960277,461328446,685542482,769686596,250132798,844548596,606256201,529475170,141051905,183182143,987567751,227861902,188326591,311361511,978842741,668347653,663085695,557630148,411810252,338806497,269002484,932479451,350666631,625613504,29598680,768070128,947165944,451496307,202420613,511712925,169010989,697049447,314174842,803510978,934568058,767039154,335561522,998122314,707153365,955962838,790117460,381993581,399946982,585833560,340275438,455892947,993113966,740279506,215576594,504979755,687631463,912185122,180654413,628874740,466295837,401086702,767772868,526998814,913070302,654847341,845855193,954569186,869146144,411174288,302065000,99031742,676432485,379953459,528205879,214065055,955396651,440091654,581897146,792172797,181446912,508694905,751221296,733325229,641360496,530678609,106663512,802494606,389766638,358490394,628153170,696751528,544523940,821877373,817001374,140900710,780352631,170088487,563882417,906208853,707834334,442612743,209890053,358668634,776823378,453200108,678207077,85563161,634295036,725866667,369498272,201344266,597685069,141197599,186742968,305876927,370036210,922613559,567347587,343290971,704813107,351255824,855559276,327117467,115221748,305925845,857998304,174393966,863600015,945472674,782802998,835403803,827364117,985109240,200776469,153914120,435739237,149908162,332204058,346574616,914994395,707503072,903173838,463093625,871931195,437152169,880677884,923969754,772815220,703276096,498706956,426834715,213003871,42654811,638878050,272277788,36926502,548524519,850742276,890131638,404294298,698622358,328657542,257884670,718452906,121239900,465441364,565276373,458154470,582898738,773261535,57762860,540481076,51276814,118297561,354140479,322980576,254560507,397117153,42412273,861282435,496596534,516729763,427428482,255516496,441690002,112955049,673634069,932332534,370839451,299914796,635853943,781637119,142566316,326427685,583507359,332399696,50326828,943336844,910443903,35749377,215443166,210378363,889010600,239171332,989327120,420913874,502885445,304554568,297890859,511047350,94928442,232812054,803393810,627524218,559567668,745370879,116891814,956461923,848486262,702083756,28210487,492415453,485041666,178926604,92752101,509221735,173505841,965575417,993672258,365690123,659427532,309916340,414010548,665449983,584897483,316081400,423837281,30852609,947671496,123072854,417024705,228393536,67023481,173058257,969772067,858642748,972833708,855953933,566246403,109044750,853033609,554030549,588456333,124272981,13149875,149488426,620961073,73907336,681450486,110139256,217541745,603824768,867714285,566465272,256854705,473740345,539834793,759086433,332132854,47345871,735665345,571110044,259725799,271397836,495009953,977892621,107397924,505937737,46807755,832786717,554039538,739836639,699718004,686584769,41840048,815699207,398788777,951530358,641507274,14573445,55608304,730761548,186994068,365947341,286117569,992727261,651980380,725002217,966728302,774504074,493620659,425787152,78392904,202902901,294521587,32477608,8665074,385805547,6480445,195386063,882905710,827086114,419976654,770961665,370326640,540108111,27965496,320501160,936931943,716250047,885472894,362449689,901037986,617543365,616998411,241689023,170800444,917689000,492665053,455581044,439048298,617878267,546153800,410832876,583647241,159962833,689688906,111958134,422788075,599083638,591275729,477788714,287353959,294794454,549235263,664976878,605831531,224742211,674721958,591151127,261182882,148375062,149303172,458127868,945079846,903475954,306857338,223448490,485338097,253295020,112255769,832439988,508067579,885813406,615080882,478266578,264704022,375854262,11592187,617213117,950833252,672648814,801094388,673537569,783500912,314677225,390292613,560212593,136487514,952379341,305605536,778178240,80399358,108527695,364517875,615476531,87985631,327325061,841053509,840589341,149910851,705613192,511891006,183860274,402951877,278826144,461493120,422910344,966060100,862957781,108741372,811244417,979956704,227905886,575843485,437451184,851575824,97320633,80446553,10062353,866853135,743985752,387542350,64096308,495536568,778958865,616149734,95892879,137790981,149849619,43091355,123653954,608135077,524284512,946248707,777455009,64000362,531109416,362555755,973270421,907230501,671796787,581916047,956302777,318608826,917934157,95036540,143756682,159238447,764343677,663535023,381989264,114176316,90625460,812737190,822475440,868255716,931705982,523036626,911182075,637755328,714514568,322757463,214180453,585616335,131136757,301173212,536927485,856308259,570838465,627248482,388362300,856010965,327124767,28680245,640429013,869472373,35647565,506505511,504044999,636775888,114780136,322940537,871290956,559853523,28562509,346511325,758817457,456236253,592147133,566830709,837152536,348688123,400530159,208275743,939762089,949536364,740104173,781037696,474764743,417184051,985692352,605158240,586639535,682621270,934354567,364921909,803473094,981203923,382925569,28968316,874241506,994025245,780533430,213419642,476659737,58211426,353127732,237392044,966195358,46389172,499669418,415286796,75851112,726204947,346517073,

D没看

E看了半天才发现这家伙只会在大于两次的一个块里复读一次

F求一个点是否在凸包内

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
typedef long long ll;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int MAXN = 100004;

int n, m, k;
struct Point
{
	int x, y;
}pnt[MAXN];
struct Segment
{
	int vx, vy;
	Segment() {}
	Segment(Point po, Point pt)
	{
		vx = pt.x - po.x;
		vy = pt.y - po.y;
	}
	ll operator * (const Segment & rhs) const
	{
		return ll(vx) * ll(rhs.vx) + ll(vy) * ll(rhs.vy);
	}
	ll operator ^ (const Segment & rhs) const
	{
		return ll(vx) * ll(rhs.vy) - ll(vy) * ll(rhs.vx);
	}
};

bool cmpXY(const Point & lhs, const Point & rhs)
{
	return lhs.y != rhs.y ? lhs.y < rhs.y : lhs.x < rhs.x;
}
bool cmpPK(const Point & lhs, const Point & rhs)
{
	return (Segment(pnt[0], lhs) ^ Segment(pnt[0], rhs)) > 0;
}
bool inPolygon(const Point & pt)
{
	int low = 1, high = n - 2, mid = (low + high) / 2, res = -1;
	bool sign = false;
	int token;
	ll flag[2];
	while (low <= high){
		mid = (low + high) / 2;
		flag[0] = (Segment(pnt[0], pt) ^ Segment(pnt[0], pnt[mid]));
		if (0 == flag[0]){
			sign = true;
			token = mid;
			break ;
		}
		flag[1] = (Segment(pnt[0], pt) ^ Segment(pnt[0], pnt[mid + 1]));
		if (0 == flag[1]){
			sign = true;
			token = mid + 1;
			break ;
		}
		if (flag[0] < 0 && flag[1] > 0 || flag[0] > 0 && flag[1] < 0){
			res = mid;
			break ;
		}
		if (flag[0] < 0 && flag[1] < 0)
			low = mid + 1;
		else
			high = mid - 1;
	}
	if (sign){
		if ((Segment(pnt[0], pt) * Segment(pnt[token], pt)) <= 0)
			return true;
		return false;
	}
	if (-1 == res)
		return false;
	return (Segment(pnt[mid], pt) ^ Segment(pnt[mid], pnt[mid + 1])) <= 0;
}
int main()
{
	Point pt;
	int cnt,t;
	scanf("%d",&t);
	while (t--)
	{
	    scanf("%d%d",&n,&m);
		for (int i = 0; i < n; ++i)
			scanf("%d%d", &pnt[i].x, &pnt[i].y);
		sort(pnt, pnt + n, cmpXY);
		sort(pnt + 1, pnt + n, cmpPK);
		pnt[n] = pnt[0];
		cnt = 0;
		for(int i=0;i

G没看

H二进制枚举+miller_rabin素数判断,t了5才发现自己的快速乘不是O(1)的

#include
using namespace std;
typedef unsigned long long ll;
std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch().count());
const int maxn = 1e3+7;
int a[25],t,n,cur,ans,d;
ll MMul(ll x,ll y,ll mod,ll ans = 0){
    return (x * y - (long long)(x / (long double)mod * y + 1e-3) *mod + mod) % mod;
}
ll MExp(ll a,ll b,ll mod,ll ans = 1){
    for(a %= mod;b;b>>=1){
        if(b&1)ans = MMul(ans,a,mod);
        a = MMul(a,a,mod);
    }
    return ans;
}
bool miller_rabin(ll n,ll u = 0,int t = 0,int s = 10){
    if(n == 2)return true;
    if(n<2||!(n&1))return false;/// <2 || %2==0
    for(t = 0,u = n-1;!(u&1);t++,u>>=1);///n-1=u*2^t
    while(s--){/// s time
        ll a = generator()%(n-1)+1;
        ll x = MExp(a,u,n);///a^u
        for(int i=0;id)continue;
            for(int j=0;j>j)&1)
                p += a[j];
            if(miller_rabin(p))ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

I原来没看(不该挂机的),现在补题,倒着来一遍弗洛伊德

因为题目没有放出来所以还不知道代码能不能过

#include
using namespace std;
typedef long long ll;
const int maxn = 303;
int n,t,a[maxn];
ll A[maxn][maxn],ans[maxn];
int main(){
    scanf("%d",&t);
    while(t--){
        vector Set;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
            scanf("%lld",&A[i][j]);
        }
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        ll pt = 0;
        for(int i=n;i;i--){
            int k = a[i];
            for(auto i:Set)pt += A[k][i]+A[i][k];
            Set.push_back(a[i]);
            for(auto i:Set){
                for(auto j:Set){
                    if(A[i][k]+A[k][j]

J没看

K

emmm,看代码吧

#include
using namespace std;
typedef long long ll;
int n,t,x;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int a[32] = {0};
        for(int i=0;i>i)&1){
                a[i] ^= x;break;
            }
        }
        for(int i=30;~i;i--)if(a[i]){
            for(int j=i-1;~j;j--)if(a[j]){
                printf("%d %d\n",a[j],a[i]);
                break;
            }
        }
    }
    return 0;
}

 

 

你可能感兴趣的:(某次比赛)