Solved Problem ID Title Ratio (Accepted / Submitted)
1001 Pandaemonium Asphodelos: The First Circle (Savage) 14.69% (42/286)
1002 Jo loves counting 12.54% (70/558)
1003 Slipper 13.17% (548/4161)
1004 The Surveying 21.09% (93/441)
1005 3D Puzzles 5.33% (4/75)
1006 BBQ 9.82% (119/1212)
1007 Count Set 16.94% (270/1594)
1008 AC/DC 9.56% (26/272)
1009 Cube Rotate 10.47% (9/86)
1010 Bragging Dice 34.42% (789/2292)
1011 Kazuha’s String 19.69% (25/127)
1012 Buy Figurines 21.09% (669/3172)
1010 Bragging Dice
Problem Description
In the mysterious accient East, there is an ancient dice game - “bragging”. Now YahAHa and Peanut is playing bragging.
The rules of the game are as follows:
There are 22 players in one game. Each player has nn dices in the cup. Both players roll the dice once.
Players play in turns. YahAHa start. In the first turn, YahAHa can claim “there are x(x\geq 1)x(x≥1) dices with y(1\leq y\leq 6)y(1≤y≤6) points in the 2 cups”.
Then Peanut has 22 choices.
Challenge YahAHa. If anyone challenges, the game is over . Each player opens its cup. If indeed there are xx dices with yy points in the cups, YahAHa wins, otherwise Peanut wins.
Continue to claim, but can only claim "there are x_1x
1
(x_1>x)(x
1
x) dices with y_1(1\leq y_1\leq 6)y
1
(1≤y
1
≤6) points in the cups" or “there are x_2x
2
(x_2=x)(x
2
=x) dices with y_2y
2
(y_2 > y)(y
2
y) points in the cups”.
After Peanut claimed, YahAHa continued to choose whether to challenge or claim. Both players take turns until someone challenges, then the game is over.
To make the game more interesting, here are some special rules.
If no one has claimed that “there are xx dices with 11 point in the cups”, the dice with 11 point can be regarded as any points of dice.
If all dices in one cup has the same points, it’s considered there is an extra dice with the same points. For example, if there are 55 dices and 55 dices are all with 66 points, it’s considered there are 66 dices with 66 points.
If each dice in one cup has different points, it’s considered “there are 00 dice with any points in the cup”. For example, if there are 55 dices,their points are 11 point, 22 points, 33 points, 44 points and 55 points. It’s considered “there are 00 dice with 11 point in the cup”, “there are 00 dice with 22 point in the cup”, … , “there are 00 dice with 55 point in the cup”.
If there is conflict in these three rules, please consider the third special rule first.
YahAHa and Peanut don’t like stupid game of chance, so they want to play this game while knowing the points of every dices in the 2 cups.
Given you the points of all dices they roll. YahAHa wants to find out who will win the game if both of them play the game optimally.
Input
Each test contains multiple test cases. The first line contains the number of test cases (1 \le T \le 30)(1≤T≤30). Description of the test cases follows.
The first line of the input contains only one integers nn (2\le n \le 2\times 10^5)(2≤n≤2×10
5
) indicating the number of dices.
The next line contains nn integers a_1, a_2, \cdots, a_na
1
,a
2
,⋯,a
n
. The ii-th integer a_ia
i
indicating the points of the ii-th dice from YahAHa.
The next line contains nn integers b_1, b_2, \cdots, b_nb
1
,b
2
,⋯,b
n
. The ii-th integer b_ib
i
indicating the points of the ii-th dice from Peanut.
Output
For each test case:
If YahAHa wins, print “Win!” in one line; If Peanut wins, print “Just a game of chance.” in one line.
Sample Input
1
5
4 6 4 1 2
3 6 6 2 3
Sample Output
Win!
题意:
思路:
#include
using namespace std;
const int maxn = 2e5+10;
int main(){
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);//TLE
int T; cin>>T;
while(T--){
int n; cin>>n;
int a[10] = {0}, b[10] = {0}, x;
for(int i = 1; i <= n; i++)cin>>x, a[x]++;
for(int i = 1; i <= n; i++)cin>>x, b[x]++;
int ok = 0;
for(int i = 1; i <= 6; i++){
if(a[i]>1 || b[i]>1)ok = 1;
}
if(ok)cout<<"Win!\n";
else cout<<"Just a game of chance.\n";
}
return 0;
}
1012 Buy Figurines
Problem Description
During the “Hues of the Violet Garden” event, As the professional Lady Guuji hired, Sayu is assigned to buy one of the figurines, that is “Status of Her Excellency, the Almighty Narukami Ogosho, God of Thunder”.
There are nn people numbered from 11 to nn who intent to buy a figurine and the store has mm windows with mm queues identified from 11 to mm. The ii-th person has an arrival time a_ia
i
and a spent time s_is
i
to buy a figurine(It guaranteed that everyone’s arrival time a_ia
i
is different). When a person arrives at the store, he will choose the queue with the least number of people to queue. If there are multiple queues with the least number of people, he will choose the queue with the smallest identifier. It should be noted that if someone leaves the queue at the same time, the person will choose the queue after everyone leaves the team.
Sayu has been here since last night so she could buy a figurine. But after waiting and waiting, her eyes started to feel real droopy and… overslept. If Sayu doesn’t buy one of these figurines, the Tenryou Commission tengu will lock her up for life! The store will close after these nn people buy figurines, that means she must wake up before the last one leaves. Now Lady Guuji wants to know the latest time Sayu wakes up.
For example, there are two people in the same line, a_1=1, s_1=2, a_2=2, s_2=2a
1
=1,s
1
=2,a
2
=2,s
2
=2. When the first person arrives, there is no one in the line, so the start time and end time of purchasing the figurine are 11 and 33. When the second person arrives, the first person is still in line, so the start time and end time of purchasing the figurine are 33 and 55. And if the end time of the last person is xx, the answer is xx.
Input
The first line contains one integer TT (1 \le T \le 10)(1≤T≤10) .
The first line of each test case contains two positive integers nn and mm (1\le n \le 2 \times 10^5,1\le m \le 2 \times 10^5)(1≤n≤2×10
5
,1≤m≤2×10
5
) — the number of people and the number of queues.
Then, nn lines follow, each consisting of two integers a_ia
i
and s_is
i
(1\le a_i,s_i \le 10^9)(1≤a
i
,s
i
≤10
9
) — the arrival time and spent time of ii-th person.
It guaranteed that the sum of nn does not exceed 2 \times 10^62×10
6
, and the sum of mm does not exceed 2 \times 10^62×10
6
.
Output
For each test case:
print a line containing a single integer — the latest time Sayu wakes up, that means the end time of the last person.
Sample Input
1
5 3
2 4
1 3
5 1
3 4
4 2
Sample Output
7
题意
思路:
#include
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;
struct node{ LL x, s;}a[maxn];
bool cmp(node x, node y){ return x.x<y.x; }
deque<LL>q[maxn]; //队伍i中每个人的结束时间
int main(){
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
// 输入
int n, m; cin>>n>>m;
for(int i = 1; i <= n; i++)cin>>a[i].x>>a[i].s;
sort(a+1,a+n+1,cmp);
// 空队伍(下标), 非空队伍(长度,下标), 小根堆(结束时间, 下标)
set<int>se; set<pair<int,int> >se2;
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> >p;
for(int i = 1; i <= m; i++)se.insert(i), q[i].clear();
// 依次入队
for(int i = 1; i <= n; i++){
//找到最早结束的队, 不断出队 (保证当前有空队伍)
while(p.size() && p.top().first <= a[i].x){
int id = p.top().second; p.pop();
se2.erase(make_pair(q[id].size(),id));
q[id].pop_front();
if(q[id].empty())se.insert(id);
else {
se2.insert({q[id].size(), id});
p.push({q[id].front(), id});
}
}
//空队伍>最短的队伍>下标小的队伍
if(se.size() > 0){
int id = *se.begin(); se.erase(id);
q[id].push_back(a[i].x+a[i].s);
se2.insert({1,id});
p.push({a[i].x+a[i].s, id});
}else{
int id=se2.begin()->second, len=se2.begin()->first; se2.erase(se2.begin());
q[id].push_back(max(q[id].back(), a[i].x)+a[i].s);
se2.insert({len+1,id});
}
}
LL ans = 0;
for(auto x : se2)ans = max(ans, q[x.second].back());
cout<<ans<<"\n";
}
return 0;
}
Slipper
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/262144 K (Java/Others)
Total Submission(s): 717 Accepted Submission(s): 160
Problem Description
Gi is a naughty child. He often does some strange things. Therefore, his father decides to play a game with him.
Gi’s father is a senior magician, he teleports Gi and Gi’s Slipper into a labyrinth. To simplify this problem, we regard the labyrinth as a tree with n nodes, rooted at node 1. Gi is initially at node s, and his slipper is at node t. In the tree, going through any edge between two nodes costs w unit of power.
Gi is also a little magician! He can use his magic to teleport to any other node, if the depth difference between these two nodes equals to k. That is, if two nodes u,v satisfying that |depu−depv|=k, then Gi can teleport from u to v or from v to u. But each time when he uses magic he needs to consume p unit of power. Note that he can use his magic any times.
Gi want to take his slipper with minimum unit of power.
Input
Each test contains multiple test cases. The first line contains the number of test cases (1≤T≤5). Description of the test cases follows.
The first line contains an integer n — The number of nodes in the tree. 2≤n≤106.
The following n−1 lines contains 3 integers u,v,w that means there is an edge between nodes u and v. Going through this edge costs w unit of power. 1≤u,v≤n,1≤w≤106.
The next line will contain two separated integers k,p. 1≤k≤maxu⊆V(depu),0≤p≤106.
The last line contains two positive integers s,t, denoting the positions of Gi and slipper. 1≤s≤n,1≤t≤n. It is guaranteed the s≠t.
Output
For each test case:
Print an integer in a line — the minimum unit of power Gi needs.
Sample Input
1
6
6 1 2
3 5 2
2 4 6
5 2 2
5 6 20
3 8
6 5
Sample Output
12
Hint
Example1: Gi can go from node 6 to node 1 using 2 units of power. Then he teleports from node 1 to node 2 using 8 units of power. Finally, he goes from node 2 to node 5 using 2 units of power. Total cost=2+8+2=12
Source
2022“杭电杯”中国大学生算法设计超级联赛(5)
题意:
思路:
//链式前向星, AC
#include
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const int maxn = 2e6+10;//+n层
//Graph
int n, m = 0;
int head[maxn];
struct Edge{ int to, next, w; }edge[maxn*3];
void add_edge(int u, int v, int w){
edge[m].to = v;
edge[m].next = head[u];
edge[m].w = w;
head[u] = m++;
}
int depp[maxn], mxdep = 0;
void dfs(int u, int fa, int d){
mxdep = max(mxdep, d);
depp[u] = d;
for(int j = head[u]; j != -1; j = edge[j].next){
if(edge[j].to == fa)continue;
dfs(edge[j].to, u, d+1);
}
}
//Dijkstra
int k, p;
int st, ed;
LL dist[maxn];
bool vis[maxn];
void dijkstra(int st, LL dis[]){
for(int i = 0; i <= 2*n+10; i++) dis[i]=1e18, vis[i] = 0;
priority_queue< P,vector<P>, greater<P> >que;
dis[st] = 0;
que.push({dis[st],st});
while(!que.empty()){
P now=que.top(); que.pop();
int u=now.second;
if(vis[u]) continue;
vis[u]=1;
for(int j = head[u]; j != -1; j = edge[j].next){
int v=edge[j].to;
if(vis[v]) continue;
int cost=edge[j].w;
if(dis[v]>dis[u]+cost){
dis[v]=dis[u]+cost;
que.push({dis[v],v});
}
}
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
cin>>n;
mxdep = 0, m = 0; //TLE
for(int i = 0; i <= 2*n+5; i++) head[i] = -1;
for(int i = 1; i < n; i++){
int u, v, w; cin>>u>>v>>w;
add_edge(u,v,w);
add_edge(v,u,w);
}
//预处理+建图
dfs(1,0, 1);
cin>>k>>p; cin>>st>>ed;
for(int i = 1; i <= n; i++){
add_edge(i, depp[i] + n + 1, 0);
if(depp[i]+k<=mxdep){
// add_edge(i, depp[i]+n+1+k, p); //WA
add_edge(depp[i]+n+1+k, i, p);
}
if(depp[i]-k>0){
// add_edge(i, depp[i]+n+1-k, p);
add_edge(depp[i]+n+1-k, i, p);
}
}
dijkstra(st, dist);
cout<<dist[ed]<<"\n";
}
return 0;
}
//vector, RE
#include
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const int maxn = 6e6+10;//+n层
//Graph
int n, m = 0;
struct node{int to, w;};
vector<node>G[maxn];
int depp[maxn], mxdep = 0;
void dfs(int u, int fa, int d){
mxdep = max(mxdep, d);
depp[u] = d;
for(auto v : G[u]){
if(v.to==fa)continue;
dfs(v.to, u, d+1);
}
}
//Dijkstra
int k, p;
int st, ed;
LL dist[maxn];
bool vis[maxn];
void dijkstra(int st, LL dis[]){
for(int i = 0; i <= 3*n+10; i++) dis[i]=1e18, vis[i] = 0;
priority_queue< P,vector<P>, greater<P> >que;
dis[st] = 0;
que.push({dis[st],st});
while(!que.empty()){
P now=que.top(); que.pop();
int u=now.second;
if(vis[u]) continue;
vis[u]=1;
for(int i=0;i<G[u].size();i++){
int v=G[u][i].to;
int cost=G[u][i].w;
if(dis[v]>dis[u]+cost){
dis[v]=dis[u]+cost;
que.push({dis[v],v});
}
}
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
cin>>n;
mxdep = 0, m = 0; //TLE
for(int i = 1; i < n; i++){
int u, v, w; cin>>u>>v>>w;
G[u].push_back({v,w});
G[v].push_back({u,w});
}
//预处理+建图
dfs(1, 0, 1);
cin>>k>>p; cin>>st>>ed;
for(int i = 1; i <= n; i++){
G[i].push_back({depp[i]+n+1,0});
if(depp[i]+k<=mxdep){
G[depp[i]+n+1+k].push_back({i,p});
}
if(depp[i]-k>0){
G[depp[i]+n+1-k].push_back({i,p});
}
}
dijkstra(st, dist);
cout<<dist[ed]<<"\n";
}
return 0;
}