提交 8558ccd0 编写于 作者: CSDN问答's avatar CSDN问答

add exercises

上级 146d7f44
1 -1 0 0 -1
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
1 0 0 0 1
\ No newline at end of file
1 -1 1 -1 1
-1 1 -1 1 -1
1 -1 1 -1 1
-1 1 -1 1 -1
1 -1 1 -1 1
\ No newline at end of file
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
\ No newline at end of file
1 -1 -1 -1 -1
-1 1 -1 -1 -1
-1 -1 1 -1 -1
-1 -1 -1 1 -1
-1 -1 -1 -1 1
\ No newline at end of file
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
\ No newline at end of file
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
\ No newline at end of file
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
\ No newline at end of file
1 -1 1 -1 1
-1 1 -1 1 -1
1 -1 1 -1 1
-1 1 -1 1 -1
1 -1 1 -1 1
\ No newline at end of file
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
\ No newline at end of file
1 -1 -1 -1 -1
-1 1 -1 -1 -1
-1 -1 1 -1 -1
-1 -1 -1 1 -1
-1 -1 -1 -1 1
\ No newline at end of file
Don Corleone
Fredo Corleone
Michael Corleone
Tom Hagen
Santino Corleone
\ No newline at end of file
Don Corleone
Fredo Corleone
Tom Hagen
\ No newline at end of file
1
Don Corleone is the Don's son
\ No newline at end of file
Don Corleone
Fredo Corleone
Tom Hagen
\ No newline at end of file
Don Corleone
Fredo Corleone
Tom Hagen
\ No newline at end of file
Don Corleone
Fredo Corleone
Tom Hagen
\ No newline at end of file
Don Corleone
Fredo Corleone
Michael Corleone
Tom Hagen
\ No newline at end of file
Don Corleone
Fredo Corleone
Michael Corleone
Tom Hagen
Santino Corleone
\ No newline at end of file
# 大整数替换数位
以字符串的形式给你一个长度为 M 的整数 N,请你计算出对这个数进行一次操作后模 9 的值为 1 的所有可能的不同操作方式。
在一次操作中, 我们可以选择 N 的一个数位 N[i],并把它替换成另一个不同的 0 到 9 范围之内的数 B,两种操作方式不同当且仅当它们选择的 i 或 B 不同。
## 输入描述
第一行包含一个整数 M (1 <= M <= 100000)。
第二行包含一个大整数 N。
## 输出格式
第一行输出一个整数, 代表对 N 执行一次操作后使 N 模 9 的值为 1 的所有可能的不同操作方式数量。
## 输入用例
4
2345
## 输出用例
5
## 提示
一共有 5 种不同的操作方式使操作后的数模 9 = 1。
前两种是:
i = 0, B = 7
7345 % 9 = 1
i = 1, B = 8
2845 % 9 = 1
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << x << endl
#define out2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << endl
#define no cout << "No" << endl; return
#define yes cout << "Yes" << endl; return
#define outvec(a) for (int v : a) { cout << v << ' '; } cout << endl
#define lowbit(x) (x & -x)
#define gcd __gcd
#define inf 0x3f3f3f3f3f3f3f3fLL
#define infi 0x3f3f3f3f
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n;
string s;
cin >> n >> s;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += s[i] - '0';
}
int ans = 0;
for (int i = 0; i < n; i++) {
int k = s[i] - '0';
for (int j = 0; j < 10; j++) {
if (j == k) continue;
if ((sum - k + j) % 9 == 1) {
ans++;
}
}
}
cout << ans << endl;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
10004
114091039852357218710108699296210685022101090621067104584969381083471010850212410411049104293610107522641090090049045244537876329557753751650512545265924742826110871902910107743862510785442185675100611006604432575375260021026569101010794177135687069406221271058965142444539106244102102699975201810061010631482101058100909613539810624287778146696710649930410829067941700882895031032852576198109845710975101643846740998955853101008960108987610101010102217710737378482819504541850105283982587854395125615111547096298306270310071010610241290621019108554324695704702912333092659874161080386941087103099663730117832802638653217136871010881104853143114353913264729798210395051031056810167910730684464102511068301009105481110308060054840329266523767163443826152106101621055810480868108081036507043905351344468468610122025803748110924109345521063794052155926987633751061084230189684655577141086971020758477196410424566464093059230063801096410104100899106514101096534978410502541580394510816510650000110610851049442310400075551031104073744560045711005839107121014672610461513710616554514981577419980171107110395010571032601007658252261815101609660610453861528790105575810781078503670914865295479411178733182363103992759451235279187150658108684117709577162848751061036243142239110634238190824463317370910701043041363491910433803525212002857151801673310465048010371110025056810602388547829075900436693687104251304231049974547617976671210114027051006191014462004835645619102278863581684489255215449633318104573514591610220791042369910152876930601149644490644261002110801015489618557810010182524970251029455138825061035576759103224610352233106811043871450964952614107296081046912001057604740010587793527694436624305497064103294167100881476578105237401010779710926103679692951038400346107319544681810458410106693337185131081514158821109636002711093587547769810034127410637176373215210429898092465252105124001021071080207716176993747463917210010598666804006105297381994523681477751365289994368156364563751342105509054351015341104427108710443826354510899100457186870301108610041010109340010401455304628751092781359286828511680256151907242852618131212108100409181036104367101256485101048529555775701086628128063228227758770502326840101743712141043820754369301121021061090522699928064864113441075047425755410663482441099899910231079167616102105465512909101011682017101092799510884697771066387636712670701081067104104910251570333847610945931002172904177933661106873871102290889746907695291926102410689841457910122101062105697999546697710010220311310610063683231101621010042539759497877116908705319921401083182693501391088510711099751045873706689644354272210413618095239685465073662437678210421497666282726487109691210852610107938636101101011451810241020134100102635151045614100444389207042922510074218144466410352831033873697841015152785420104601055102467283549988591321864498200102082624742134489001554648919266161012788333708074951081739461010437695154469782358181785223994438039699010894015924688594705198131040935683088021049110293106921102503325505010691610126930127279870498103691024903102090577249341020107734258246540718013822311060520983931065935719168104941901010630160106010629181019208100829301077972704103238176137048154886210790795165808498410250171661086557683374793992831061065532310562149410391398810310303961769271010031064155127669150774500101083981755238108055204321107932943717194185061051010392818102933828854707575774526878363636910701809571071020938101194645910222276109651028110617409816588041423845097581067115215591711635937710622162590148104891061018251010137109510610933210133985102574322864634100951335603733101017552761408197631010794101065781152800610976358986332837961009326008102710374495908633442364988295216484883683645946768736192333010620110111050750569777608985437810410451074661078966125414100849784651100107877130100910808710433990647460723005692338348663109598385034566553098971982406566104836710103004671068895101445106351723962106510939110510415112530106350978885910651923910128563104591017110179857296061022301083710710101081963915151333170222219180439325162922210231687751054930100109311756076577439010028102203101037270442472749545571992377824152488599501684970406813260772204033891101851051053509265965103010976772872804339343711410062159100646906436410953921287865696248954371041138156435105170104108210258103803260885171579010414451818410102110134956568608010102991021009495584513702651019576910051032010892515541002102610510388982484571035714897803101155102510552489869422410963253735184828781041077210104693775160106670177356144843826696890361470310731061559037040136560132931028081087558632557971054034682916748910781065022939114005310107131627106519461010105105515430216249103884621473422330461761050013849540859199694562260247478351081352451982210625785102684369610517210402463210526365330964109017958910761088282897366545100461391139410106106609025656856101109436016603656412109098606424279224505269105801095020855577950932655442821508509232191210308297857315116661079705598448199901261391076659991941102007888189607890410081676466810567104815110282238438304100819025100789704410798704154910292124416926134271029626556038810436104643935102296710261699783510347082600361041840550883091628527530471101051061063282141051094101456642857706123507411480301070101076137761051849798104549587449121052971522136591937436204634101012241041681761022851341310424460283510101881065297106446569522356648209600188110100108990127682031074585237481071702101031073907210015914389365549747353210019697551103810104632081943896007011102997807807228428863975056598510457460822047694102508496108897532704578070841010900991304878731110830107181896352536210501047710145546804651080510719581231001064779080105863311203256948975610622890103516109646981010610810791871045843151403734495103671089681010688044247819107432397743906619102610632121102973269071836875396102470266935107381080940053105383221791038075439100416864563671030106695421034171372095388645440107270191910109408917104810709997391249102293141418989010737191252210481422910921999069329410536704072831270674696210101810659054213982092898110722179218810365495408301010190968104061090039909949106108896772110676096983643981091091592287064841037102193522105801102141509106935618947432611279845452190253101099013326498106032507036207345510850454643105681610236862440021012983106109660093393777274058311047731052347301066004598345442871300469350272611103715488568215337775705293023108994240106300101009515327724919102701048639684955344263980102178344210503731123710472751080851810106898088461144610828068640828742291069102796914176210227931292432688633370018571847753405246247080092373785551097108329810810442441053464109876935331070567507503301210231010884872707335071910108521642791719662071058489810872470630951695432236211100651194241169774301510310081060698029937070238977614108434614108541881046645510421855810289191242892904511370010100709319846047465988341710102351824106086109954110231027420101930494658329533059246036812104959056661343109845972710766573464733855985777951064103137565235665194032710000481081233808104520054985710508445752941610503682549102058100171241727524610422107535462713102480111185189005880832657100933103470861498577802288492009251635986488757061013911687404512692782537040276841359663179102475189810719185010889686769259995788145108140107710304751633440758338288200791014798545231410241100177105892529800289104166540894036810551108077912186910287831026210166532960610264290858471121010749590026910925010789529357821034153609161003201852908691105105102576934717774104210910540455441532181090768197751876923589941051033077830886241272307454261058102672696003759937761021410570610627933510593248069087910896333556101007703358316622736100492686550109941022510958948902117336971081034037399511053662013058106443097289522306101725910105372108337482842145148297172429451364810800619327843932277904410200069896623065189102217986104478064431015996475695611022459611046107910154335931241058324806195241014109110764610744079859026172868201054401041284498447484637010191043723043102854721638701096715526762476961030100222154672151040239147698471014510682080924561791189629207630952481311961159831970006345106161053110304059109810621086574191359863530536501795014940338103109215310355454960711127910959109766177101057452356774599055710866885492642439448198012136019047802572384059589620270861010320073318464578121065393101034734738494665338188968450587991310314910443722392817657803910909255498999310271022710046993910003073550561059100138869711790929728151037800238762780444062584344730157221071088239967710605006575431882421106310762371068663103102127749517769959510224101080124457310249850845484588102510100387935681310110022213310038668181005625482741061499104544147603913511061668836104861633108169102894564030024214889108020933415531794465284827208765793239980140284008600710910467010513787578041879298908395102972225029710315020615912910096759015496120673161588510789914506765810118103609628347633556102080182100925106861105038825103048841878132231053844757315222770109290987295249101077378103604980208710176110611210378839553595113849624074391762070009272758210883143394226395551340510943821497874928410215981071043817106342764031053101216105001711010418921850257109441061065728873966578921224164343055858815501032674104127062361029301010760107610373775681046951061078664930991510255535880816115102071150466224652195663311422862151049350688651391056511565381081836969107112007887532735518398872314466881136023971029667604129275869093082896510653165464596276407134197626966105747350643621075437210974838931017101086707731385745179100102858108777850530314591065101197110291077811014433510125106931612216107953757251031125221289981441072053733711183534104105319351241078776044630667636620210432681592985445471050045442737286663310104959095308818281065156513975109848106410254467111078930121486143264501075975580209211094600428985719359196318851142047039110118706027089481010139131103622068821941146105171084226021051109310104617751008243887879817029028428841003302445913210810256758910815546891746221511125246712648281435858419266251006771110112630704107141099111850106574705103867579102810841854669091590109793700705768502994111006510994105106441086982413822393107431023905113962352104278235459177907742510229757631108158582961031566245391072430201504041084120940523292636410473523332613297109553961003846703070564514109193534228703508591610019351010110105810786247833910342257917382810301002101015658672617941045245149903854263288768967085111332739202994255727205325198084191637751068104379711910126236104841004171061106326744296178794682951065930522101080010028079062410636401030543462723484192871047066143993210401088609732701410228101075104085022107151095395217107794367539799366547614313959791032077290825911083226109651009532102472904220101010340233671067935110510333966594918103641095655331984821932145914223
# 近视的张浩扬
张浩扬和他的 M 个朋友来到了一个十分神奇的地方,在这里有 N 个 柱子, 对于每个 1 <= i <= N, 第 i 个柱子都有两个属性 : H[i], P[i]。
H[i] 表示柱子 i 的高度, 而 P[i] 则表示柱子 i 当前所处的位置,题目保证同一个位置不会有多个柱子。
在一个柱子 i 在另一个不比他低的柱子 j 的后面时 (P[i] > P[j] && H[i] <= H[j]), 这个柱子会被遮挡住, 也就不再能被清晰的看到。
张浩扬和他的朋友们在位置 0 休息时, 发现似乎朋友们能清晰看到的柱子数量并不相同,在他反复思考后, 他认为这可能是近视度数导致的,于是他询问了每一个朋友的近视度数 A[i]。
为了方便计算, 我们认为对于朋友 j 来说,对每一个柱子 i, 如果有 P[i] > A[j], 那么第 i 个柱子无法被清晰看见。(别问我为什么近视度数高了反而看的更远 :( 问就是异世界)
请你计算出每个张浩扬的朋友能清晰看到的最远一个柱子的位置, 如果那个朋友一个柱子都没有清晰看到, 请输出 -1。
## 输入描述
第一行包含两个整数 M (1 <= M <= 100000), N(1 <= N <= 100000)。
第二行包含 N 个整数, 其中第 i 个整数代表第 i 个柱子的高度 H[i] (1 <= H[i] <= 1000000000)。
第三行包含 N 个整数, 其中第 i 个整数代表第 i 个柱子的位置 P[i] (1 <= P[i] <= 1000000000)。
第四行包含 M 个整数, 其中第 i 个整数代表第 i 个张浩扬的朋友的近视度数 A[i] (1 <= A[i] <= 1000000000)。
## 输出格式
按顺序打印张浩扬每一个同学能清晰看到的最远的柱子,每个答案占一行。
## 输入用例
4 3
1 3 2
2 3 4
1 2 3 4
## 输出用例
-1
2
3
3
## 提示
对于最后一个朋友来说, 因为最后一个柱子被第 2 个柱子遮挡住了, 所以他只能看到第 2 个柱子, 而这个柱子的位置为 3。
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << x << endl
#define out2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << endl
#define no cout << "No" << endl; return
#define yes cout << "Yes" << endl; return
#define outvec(a) for (int v : a) { cout << v << ' '; } cout << endl
#define lowbit(x) (x & -x)
#define gcd __gcd
#define inf 0x3f3f3f3f3f3f3f3fLL
#define infi 0x3f3f3f3f
using ll = long long;
using pii = pair<int, int>;
void solve() {
int m, n;
cin >> m >> n;
vector<int> h(n);
vector<int> p(n);
vector<int> id(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
id[i] = i;
}
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(id.begin(), id.end(), [&](int a, int b) -> int {
return p[a] < p[b];
});
vector<int> stk;
for (int i = 0; i < n; i++) {
if (stk.empty() || h[stk.back()] < h[id[i]]) {
stk.push_back(id[i]);
}
}
for (int i = 0; i < m; i++) {
int a;
cin >> a;
int left = 0;
int right = (int) stk.size() - 1;
int ans = -1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (p[stk[mid]] > a) {
right = mid - 1;
} else {
left = mid + 1;
ans = p[stk[mid]];
}
}
cout << ans << endl;
}
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
# 张浩扬的手速大比拼
在很久很久以前,张浩扬找到了一颗有 N 个节点的有根树 T 。 树上的节点编号在 1 到 N 范围内。
他很快发现树上的每个节点 i 都有一个对应的整数值 V[i]。
一个老爷爷对他说,给你一个整数 X, 如果你能回答我的 M 个问题,他就给张浩扬购买一些零食。
对于每个问题 Q[i], 请你找到 在 T 中以节点 Q[i] 为根的子树中的所有节点(包括 Q[i])中, 有没有两个节点 A, B (A != B) 的值 V[A] ^ V[B] 的异或和为 X。
如果有这样的两个节点, 请你输出 YES。
否则你需要输出 NO 表示没有节点符合上面的条件。
## 输入描述
第一行包含三个整数 N (2 <= N <= 100000), X (0 <= X <= 1000000000),M(1 <= M <= N) , 表示树上节点的数量 和 老爷爷给的数 X 和 老爷爷的问题数量。
第二行包含 N 个数, 第 1 个数代表节点 1 的父节点, 第 2 个数代表节点 2 的父节点, 以此类推。
题目保证输入是一颗合法的有根树, 如果第 i 个数为 -1 表示 节点 i 没有父节点。
第三行包含 N 个数, 第 1 个数代表节点 1 的值 V[1], 第 2 个数代表节点 2 的值 V[2], 以此类推。
题目保证对于每一个下标1 <= i <= N 都有 0 <= V[i] <= 1000000000。
接下来有 M 行, 每一行包括一个整数Q[i] (1 <= Q[i] <= N), 代表老爷爷问张浩扬的第 i 个问题。
## 输出格式
按顺序输出问题 Q[1], Q[2] ... Q[M] 的答案, 每个答案占一行。
## 输入用例
4 2 3
-1 1 1 2
4 3 2 1
1
3
4
## 输出用例
YES
NO
NO
## 提示
第一个用例给出的树是
1(4)
2(3) 3(2)
4(1)
括号左边的数为节点编号, 括号内的数为节点值。
对于第一个测试用例的第一个问题, 显然有节点 4 与 节点 2 的值 (1 ^ 3) == 2。
对于第一个测试用例的第二个问题, 以节点 3 为根的子树里只有 3 一个节点 并没有一对节点满足 A != B 且 (V[A] ^ V[B]) == 2。
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << x << endl
#define out2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << endl
#define no cout << "No" << endl; return
#define yes cout << "Yes" << endl; return
#define outvec(a) for (int v : a) { cout << v << ' '; } cout << endl
#define lowbit(x) (x & -x)
#define gcd __gcd
#define inf 0x3f3f3f3f3f3f3f3fLL
#define infi 0x3f3f3f3f
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n, x, m;
cin >> n >> x >> m;
vector<vector<int>> graph(n + 1);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
cin >> p[i];
if (p[i] != -1) graph[p[i]].push_back(i);
}
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int dfn = 0;
vector<int> dfns(n + 1);
vector<int> dfne(n + 1);
vector<int> idx(n + 1);
function<int(int)> dfs = [&](int node) -> int {
dfns[node] = dfne[node] = ++dfn;
idx[dfn] = node;
for (int next : graph[node]) {
dfne[node] = dfs(next);
}
return dfne[node];
};
for (int i = 1; i <= n; i++) {
if (p[i] == -1) {
dfs(i);
break;
}
}
map<int, int> mp;
vector<int> pre(n + 1);
for (int i = 1; i <= n; i++) {
pre[i] = pre[i - 1];
int back = v[idx[i]] ^ x;
if (mp.count(back)) {
pre[i] = max(pre[i], mp[back]);
}
mp[v[idx[i]]] = i;
}
for (int i = 1; i <= m; i++) {
int q;
cin >> q;
int l = dfns[q];
int r = dfne[q];
if (pre[r] < l) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
# 异或和
张浩扬找到了一个整数 N,他想问问你从 1 到 N 的所有不同整数的异或和是多少, 请你回答他的问题。
## 输入描述
第一行包含一个整数 N (1 <= N <= 100000)。
## 输出格式
第一行输出一个整数, 代表从 1 到 N 的所有不同整数的异或和。
## 输入用例
5
## 输出用例
1
## 提示
1 ^ 2 ^ 3 ^ 4 ^ 5 = 3 ^ 3 ^ 4 ^ 5 = 4 ^ 5 = 1。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册