牛客練習賽 41

2021-09-11 18:53:24 字數 2223 閱讀 6901

a. 博弈 我們發現 要麼一次拿光, 要麼 m 為 1 否則都贏不了

b. dp 思路, 因為有負數, 如果全負數, 最小為 -666*300 近似於 21w 所以把錨點設為 210000,

dp [ i ] [ j ] 代表 前 i 個數字 湊夠數字 j 的方案數,

dp[ i ] [ j ] = dp [ i-1 ] [ -j ] + dp [ i-1 ] [ j-a[i] ] 

但是 開 long long 會炸 memory , 用滾動陣列

#includeusing namespace std;

#define ll long long int

const ll mod=1e8+7;

ll dp[2][444444];

int cd=200000;

ll a[305];

int main()}}

cout#includeusing namespace std;

#define ll long long int

const ll maxn=1e6+5;

ll n,m,a[maxn],t[maxn];

ll fa[maxn],ra[maxn];

ll num[maxn];

inline bool cmp(ll a, ll b)

inline ll find(ll x)

inline void unite(ll a, ll b)

inline void init(ll n)

bool vis[maxn];

int main()

sort(num+1, num+1+n, cmp);

ll ans = 0;

for(ll i=1;i<=m;i++)

ans+=num[i];

printf("%lld\n",ans);

return 0;

}

e。套個球體間公共體積板子

#include#include#include#include#include#define clr(a,b) memset(a,b,sizeof(a));

using namespace std;

const int inf=0x3f3f3f3f;

const double pi = acos(-1.0);

typedef unsigned long long ll;

const int maxn= 110;

typedef struct point

point(double a, double b,double c)

point operator -(const point &b)const

point operator +(const point &b)const

//數乘計算

point operator *(const double &k)const

point operator /(const double &k)const

double operator *(const point &b)const

}point;

double dist(point p1, point p2)

typedef struct sphere sphere;

sphere s,a[maxn];

void sphereintervs(sphere a, sphere b,double &v,double &s)

int t, n;

double x, y, z, r;

int cas = 1;

int main()

; }

scanf("%lf%lf%lf%lf",&x,&y,&z,&r);

s.r = r;

s.centre = ; //中心球

double ans = 0, v = 0, res = (4.0 / 3.0 * pi * s.r * s.r * s.r) + (4.0 / 3.0 * pi * a[1].r * a[1].r * a[1].r);

for(int i = 1; i <= 1; i++)

sphereintervs(s, a[i], v, ss); //相交部分

ans += v;

}printf("%.7f\n",res - ans);

return 0;

}

牛客練習賽41

相當於求n個點,已知n條邊,組成各個連通分塊,每個連通分塊有乙個和值,求出最大的幾個和值。用並查集給邊建立聯絡,計算連通塊和是 先找到那個fa點 再給該點加值。include include include include include includeusing namespace std typ...

牛客網練習賽 41

a 中文題意,直接說思路 可以知道在n m 0 的時候可以全部翻轉完,但當第一次翻轉完之後b使壞一次就永遠也翻不到,所以只有當n m的時候是yes其他都是no include using namespace std int main b 思路 簡單的計數dp,可以設 dp i j 表示的是你在第i輪...

BFS, D 最小相似度,牛客練習賽41,

傳送門 由於m只有20,所以我們知道狀態數一共只有2 20,我們如果能算出每個狀態和給定n個字串相似度的最大值,這道題就解決了。首先我們知道所有n個串最初的dp值為m,通過bfs,把每個串丟進佇列一次,每個串改變每一位得到新的字串,相同位少了乙個 即相似度減一,更新那些沒出現過的串的dp值再丟進佇列...