CQ18階梯賽第8場 題解

2022-04-30 14:30:06 字數 2971 閱讀 3267

【a:hdu2032 楊輝三角】:

簡單的遞推,或者是基礎的dp;

但是只有楊潤東乙個人1a,整體準確率只有8/37,具體原因不詳。

經驗:提交前一定要試一下比較特殊的資料或者最大的資料。其次,為了保險,一定要嚴格按照格式來輸出。

最後,陣列最好定義為全域性變數,i,j等定義為區域性變數。

#include#include

#include

#include

#include

using

namespace

std;

long

long f[40][40

];int

main()

printf("\n

");}

return0;

}

view code

【b:hdu2046 骨牌鋪方格】:

我們可以得到方程f[i]=f[i-1]+f[i-2],其實就是斐波拉契數列,注意要使用long long。

經驗:此題的n較小,n較大時需要用「矩陣乘法」來做。

#include#include

#include

#include

#include

#include

using

namespace

std;

inta,b;

long

long s[60

];int

main()

while(cin>>n)

return0;

}

view code

-------------------------------上面的noip第一題水平,以下是noip第二題水平------------------------------------

【c:poj2976 dropping tests】

題意:有幾門成績,現在要求選n-k門,使得平均成績最高,求最高平均成績。 

思路:01分數規劃:貪心+二分,我們二分最高平均成績ans,然後排序,得到前n-k名,看他們的平均成績是否大於等於ans。

具體實現:a/b>=ans,a-b*ans排序,越大的價值越高。證明:這裡涉及乙個式子:若a/b=c/d,則a/b=c/d=(a+c)/(b+d),所以分子之和/分母之和》=ans,那麼a/b>=ans的程度越大越好,所以根據a-b*ans排序。

#include#include

#include

#include

#include

using

namespace

std;

const

double eps=1e-6

;int

n,k;

struct

in}a[

1010

];bool check(double

mid)

intmain()

printf(

"%.0lf\n

",ans);

}return0;

}

view code

【d:hihocoder 1504 騎士遊歷】

基礎的矩陣乘法。

#include#include

#include

#include

#include

using

namespace

std;

const

int maxn=70

;#define ll long long

const

int mod=1e9+7

;int x[8]=;

int y[8]=;

struct

mat mat friend

operator *(mat a,mat b)

return

res;

}mat friend

operator ^(mat a,int

x)

return

res;

}};

mat

base

;void

prepare()

intmain()

view code

【hdu 5890:eighty seven】

題意:n個物品,分別有自己的值,q個問題,每次問拿走第x個,第y個和第z個物品後,是否能在裡面找10個物品,使其和為87。

思路:揹包問題,dp。

經驗:必須要學會使用bitset。

#include#include

#include

#include

#include

#include

using

namespace

std;

bool ans[55][55][55

];bitset

<90>s[20

];int a[60

],n;

intread()

void solve(int x,int y,int

z)

if(s[10][87]==1) ans[x][y][z]=true

;

else ans[x][y][z]=false; }

intmain()

}return0;

}

view code

總結:提交前,一定要分析的東西,資料範圍;演算法效率是否妥當。

然後,多刷題,如果可以在hdu上面刷500題,或者bzoj上面刷100道題,穩穩地拿省一(對弱省來說)。

當然,要學會挑戰難題,突破自己。

CQ18高一暑假前挑戰賽2 標程

昨晚打校賽,5個小時打完很累了,所以搞忘出題了。對不起學弟們,不過出的題都親自寫過一遍,可以保證題目和 長度都不長,題目難度不大 a bush博弈 includeusing namespace std intmain return0 b dp求最長公共子串行,可以反推字首 includeusing ...