eg:好久不見的普及組題目,自信滿滿以為自己ak了,結果c題莫名被卡常(後來開了氧氣優化就過了,我一直以為氧氣優化評測機會自己開不用手動開),d題公式精度問題被卡,最後rk14,btw牛客一場上綠還是很高興的嘿嘿嘿。
傳送門題意:統計乙個字串裡有多少個不同的字元。
題解:map或者set隨便搞。
#include
using
namespace std;
typedef
long
long ll;
const
int maxn=
1e6+10;
const
int mod=
1e9+7;
const
int inf=
0x3f3f3f3f
;ll read()
while
(ch<
'0'||ch>
'9');do
while
(ch>=
'0'&&ch<=
'9')
;return f*x;
}char s[maxn]
;map<
char
,int
>mp;
intmain()
題意:類似於統計水仙花數,一組1e6範圍。
題解:讀入乙個判斷乙個即可。
#include
using
namespace std;
typedef
long
long ll;
const
int maxn=
1e5+10;
const
int mod=
1e9+7;
const
int inf=
0x3f3f3f3f
;ll read()
while
(ch<
'0'||ch>
'9');do
while
(ch>=
'0'&&ch<=
'9')
;return f*x;
}int n,ans;
ll quick
(ll a,
int b)
return res;
}bool
check
(ll x)
xx=x;
while
(x)if
(res==xx)
return
true
;return
false;}
intmain()
printf
("%d\n"
,ans)
;return0;
}
題意:給出一顆無根樹,讓你確定他的根,使得深度之和最小。
題解:沒看懂官方題解,我的做法是找到樹的重心,然後跑一遍dfs即可。複雜度應該是o(2n),可能vector被卡常了?,以後還是記得開氧氣優化。
#pragma gcc optimize(2)
#include
using
namespace std;
typedef
long
long ll;
const
int maxn=
1e6+10;
const
int mod=
1e9+7;
const
int inf=
0x3f3f3f3f
;ll read()
while
(ch<
'0'||ch>
'9');do
while
(ch>=
'0'&&ch<=
'9')
;return f*x;
}int n,ans,size=inf;
vector<
int>g[maxn]
;int son[maxn]
,vis[maxn]
;void
dfs(
int cur)
} tmp=
max(tmp,n-son[cur]-1
);if(tmp
}ll sum=0;
void
dfs2
(int x,
int fa,
int dep)
sum=sum+
1ll*dep;
}int
main()
dfs(1)
;dfs2
(ans,-1
,0);
printf
("%lld\n"
,sum)
;return0;
}
題意:對於每個點i有pi的概率往右走,問走完n個點的期望是多少。
題解:概率dp的題目。設d
id_i
di為在當前第i個任務到結束還有多久,那麼對於第i個點它有p
ip_i
pi的概率跳到後面一天還有1−p
i1-p_i
1−pi
的概率回到前面一天,所以對應的方程就為−(1
−pi)
di−1
+di−
pidi
+1=1
-(1-p_i)d_+d_i-p_id_=1
−(1−pi
)di
−1+
di−
pid
i+1
=1,那麼列出所有的方程組,高斯消元即可解決,btw如果直接用高斯消元會有精度問題最後只能85,但如果我們直接拿on掃一遍的話就可以過了。。
#include
using
namespace std;
typedef
long
long ll;
const
int maxn=
1e5+10;
const
int mod=
1e9+7;
const
int inf=
0x3f3f3f3f
;ll read()
while
(ch<
'0'||ch>
'9');do
while
(ch>=
'0'&&ch<=
'9')
;return f*x;
}int n;
double a[maxn]
,f[maxn][5
],d[maxn]
;int
main()
牛客OI周賽14 普及組
菜的真實,普及都 ak 不掉.score 100 100 100 0 300 rank 16 看來 pj t1 考字串讀入成鐵上釘釘了?考慮開桶 a 記錄 ascii 為 i 的字元是否出現即可。includeusing namespace std typedef long long ll cons...
牛客OI周賽15 普及組部分題解
b.三角形 給定n個盒子,每個盒子中有一定數量的寶物,現在你每次可以從乙個盒子中拿取乙個寶物,這樣就會有很多種不同的價值和結果。現在問你前k小的價值結果的和是多少?n 100,k 10000,假設盒子中最多寶物數量為m,保證k n m 10000。寶物價值不超過100.首先這個題容易被資料範圍誤導,...
牛客OI周賽9 普及組
目錄a題 b題 c題 小q挺喜歡擼串的,沒錯,字串!你給小q送上了n個字串 對於乙個字串s,如果在小q擼掉 刪除 任意個字元之後,nowcoder 是其子串,則這個字串s是可擼的。小q最近切題切到手軟,想擼串散散心。如果你給他呈現的字串是可擼的,他會很開心,否則他會很桑心。輸入描述 乙個整數n,表示...