牛客小白賽專題
小白月賽8
C-神祕鑰匙:題目連結
這個題是一個規律水題,公式為n*2^(n-1),然後再用快速冪計算
#include<cstdlib> #include<algorithm> #include<string> #include<string.h> #include<cstring> #include<iostream> using namespace std; const int maxn = 1e4; typedef long long ll; ll n; ll mod = 1000000007; ll quickpow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n % 2 == 1) { res = res*x; res = res%mod; } x = x*x; //x乘以二 x = x%mod; n >>= 1; //n除以 } return res; } int main() { while(cin >> n) cout << n*quickpow(2, n - 1, mod)%mod << endl; return 0; }
F-數列操作:題目連結
這個題的正經題解是平衡樹,然而我太弱了。。。不會寫。然後在賽後查看了大佬們的程式碼,發現用vector可以暴力暴過去,所以下面附上的是vector程式碼:
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<vector> using namespace std; typedef long long ll; vector<int>vec; int num,x; int n; int main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++){ cin>>num>>x; if(num==1){ vec.insert(lower_bound(vec.begin(),vec.end(),x),x); } else if(num==2){ vec.erase(lower_bound(vec.begin(),vec.end(),x)); } else if(num==3){ cout<<lower_bound(vec.begin(),vec.end(),x)-vec.begin()+1<<endl; } else if(num==4){ cout<<vec[x-1]<<endl; } else if(num==5){ cout<<*(lower_bound(vec.begin(),vec.end(),x)-1)<<endl; } else{ cout<<*upper_bound(vec.begin(), vec.end(), x)<<endl; } } return 0; }
小白月賽9
A-簽到:題目連結
小白月賽不小白啊QAQ。。。
A題演算法就是求一個乘法逆元,下附的程式碼是用擴充套件歐幾里得寫的
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; const int mod = 1e9 + 7; typedef long long ll; ll a, b;ll p = 1;ll q = 1;ll n; ll exgcd(ll r, ll s, ll &x, ll &y) { if (s == 0) { x = 1; y = 0; return r; } ll xx, yy; ll g = exgcd(s, r%s, xx, yy); x = yy; y = xx - (r / s)*yy; return g; } ll inverse(ll r, ll s) { ll x, y; exgcd(r, s, x, y); return (x%s + s) % s; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b; p = ((b - a)*p) % mod; q = (b*q) % mod; } if (q < p)q = q + mod; ll zi = q - p, mu = q%mod; cout << (zi * (inverse(mu, mod))) % mod << endl; return 0; }
相關推薦
牛客小白賽專題
小白月賽8 C-神祕鑰匙:題目連結 這個題是一個規律水題,公式為n*2^(n-1),然後再用快速冪計算 #include<cstdlib> #include<algorithm> #include<string> #include&l
牛客小白賽4J——強迫癥
CA ofo 每一個 TP 8 8 .com sum fin com 鏈接:https://www.nowcoder.com/acm/contest/134/J 來源:牛客網 思路:把數列排序,把每一個重復的元素和最後一個數想加得到新數,在刪掉這一元素即為去重的最少步驟,
牛客小白賽---郊區春遊(狀態壓縮+floyd)
https://www.nowcoder.com/acm/contest/134/D 思路:用二進位制該位是否為1表示該點是否走過。 狀態轉移時要注意:當前點一定要走過,下一個點不能走。 #include<bits/stdc++.h> #define inf 0x3f3f3f
牛客小白賽7 部分題解
A 就是一個簡單的遞迴; 看懂就ok #include<iostream> using namespace std; int main() { long long n; cin >> n; if(n < 2018
牛客小白賽7 B自殺遊戲 (博弈論,SG函式)
時間限制:C/C++ 1秒,其他語言2秒 空間限制:C/C++ 32768K,其他語言65536K 64bit IO Format: %lld 題目描述 Alice和Bob產生了不可調節的矛盾,於是他們相約一起玩一個自殺遊戲,輸的人就會從這個世界上消失。 遊戲開始時,
牛客小白賽-簽到
你在一棟樓房下面,樓房一共有n層,第i層每秒有pi的概率會扔下一個東西並砸到你 求第一秒內你被砸到的概率 輸入描述: 第一行一個整數n 之後有n行,第i+1行有兩個整數ai,bi,表示 輸
牛客小白賽9A(求逆元)
思路: 就是求個逆元會求了,這題也就會做了。程式碼如下: #include<cstdio> #define ll long long const ll mod=1e9+7; ll qui
牛客小白賽簽到題
A 連結:https://ac.nowcoder.com/acm/contest/280/A 來源:牛客網 勘測 時間限制:C/C++ 1秒,其他語言2秒 空間限制:C/C++ 131072K,其他語言262144K 64bit IO Format: %lld 題目描述
華華和月月逛公園(牛客小白賽)
esp space return include isp while none == gis https://ac.nowcoder.com/acm/contest/392/I #include <bits/stdc++.h> using names
牛客小白月賽4
sort 暴力 n) b16 黑白 不能 close pla 浮點數 A.三角形 經典暴力:由於不能構成三角形邊長至少乘二,只用考慮最大的log個暴力 1 #include <bits/stdc++.h> 2 using namespace std;
[牛客小白月賽4 H] 相鄰的糖果
感覺 CA long ret inpu -m 執行 情況 scrip Description 有n個盒子擺成一排,每個盒子內都有ai個糖果。 現在你可以執行以下操作: ·你可以選擇任意一個盒子,在選擇的盒子內吃掉一個糖果。 對你的要求如下: ·任何m個相鄰的盒子內糖果數量不
牛客小白月賽4-E-浮點數輸出 字符串
bsp 小白 clas spa DC HA \n pan main 1 #include <bits/stdc++.h> 2 int main() 3 { 4 char a[1000]; 5 scanf("%s",a); 6 pri
牛客小白月賽4 A 三角形
() ont OS namespace 一個 分類 代碼簡潔 include str 題解+AC代碼 首先將木棍按長度排序,可以確定的是可以組成的最大三角形的三根木棍就是連著的三個如果偷走的木棍不是這三根木棍中的其中一個,那麽答案顯然,否則分類處理一下。 #inclu
牛客小白月賽5 I - 區間
poj amp using data cli oar += 一行 cst 看到一份不錯的操作。。。。。 鏈接:https://www.nowcoder.com/acm/contest/135/I 來源:牛客網 Apojacsleam喜歡數組。 他現在有
牛客小白月賽2 G 文 【模擬】
algo 思路 大小 cstring 字符 20M 所有 desc ans 鏈接:https://www.nowcoder.com/acm/contest/86/G來源:牛客網 題目描述 Sεlιнα(Selina) 開始了新一輪的男友海選。她要求她的男友要德
牛客小白月賽5-I-區間(差分數組+前綴和)
alt 前綴 -o -a 元素 describe con 圖片 整數 題目描述 Apojacsleam喜歡數組。 他現在有一個n個元素的數組a,而他要對a[L]-a[R]進行M次操作: 操作一:將a[L]-a[R]內的元素都加上P 操作二:將a[L]-a
牛客小白月賽6 F 發電
維護 max date scanf des spa 復制 best coder F 發電 題目: 鏈接:https://www.nowcoder.com/acm/contest/136/F來源:牛客網 時間限制:C/C++ 1秒,其他語言2秒 空間限制:
牛客小白月賽6 H 挖溝
i++ 來源 using 時間限制 copy tmp opera 語言 模板題 H 挖溝 題目: 鏈接:https://www.nowcoder.com/acm/contest/136/H來源:牛客網 時間限制:C/C++ 1秒,其他語言2秒 空間限制:C/
牛客小白月賽6 J 洋灰三角
題目 turn base subject ack www. -a font 備註 J 洋灰三角 題目: 鏈接:https://www.nowcoder.com/acm/contest/136/J來源:牛客網 時間限制:C/C++ 1秒,其他語言2秒 空
牛客小白月賽5
alt www. code test question inf 不等式 bubuko 小白 https://www.nowcoder.com/acm/contest/135#question 代碼: 這套題數論題不錯 B. 柯西不等式 E. F. 若