关注
(1) #include <bits/stdc++.h>
using namespace std;
inline int cal_step(int a, int b){
return int(a/10 == b/10 ? 0 : 1) + int(a%10 == b%10 ? 0 : 1);
}
int modify(int num, int range){
int res = 0, step = cal_step(num, 0);
for(int cand = 1; cand < range; cand++){
int step_tmp = cal_step(num, cand);
if(step_tmp < step){
res = cand;
step = step_tmp;
} else if(step_tmp == step && cand < res)
res = cand;
}
return res;
}
int main(){
int T, h, m, s;
scanf("%d", &T);
while(T--){
scanf("%d:%d:%d", &h, &m, &s);
printf("%02d:%02d:%02d\n", modify(h, 24), modify(m, 60), modify(s, 60));
}
return 0;
}
(2) #include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int T, m, n;
char maze[maxn][maxn];
char goal[maxn];
int goallen;
int nxt[maxn];
int search(int sx, int sy, int dx, int dy){
int x = sx, y = sy;
int curmat = 0;
int res = 0;
while(x < m && y < n){
while(maze[x][y] != goal[curmat] && curmat)
curmat = nxt[curmat];
if(maze[x][y] == goal[curmat]){
curmat = curmat + 1;
if(curmat == goallen){
res++;
curmat = nxt[curmat];
}
}
x += dx;
y += dy;
}
return res;
}
void build_next(){
nxt[0] = nxt[1] = 0;
for(int i = 2; i <= goallen; i++){
int j = i - 1;
while(j){
if( goal[i-1] == goal[nxt[j]] ){
nxt[i] = nxt[j] + 1;
break;
} else
j = nxt[j];
}
if(goal[i-1] != goal[nxt[j]])
nxt[i] = 0;
}
}
int main(){
scanf("%d", &T);
while(T--){
scanf("%d%d", &m, &n);
for(int i = 0; i < m; i++)
scanf("%s", maze[i]);
scanf("%s", goal);
goallen = strlen(goal);
build_next();
int res = 0;
for(int i = 0; i < m; i++)
res += search(i, 0, 0, 1);
for(int i = 0; i < n; i++)
res += search(0, i, 1, 0);
for(int i = 0; i < m; i++)
res += search(i, 0, 1, 1);
for(int i = 1; i < n; i++)
res += search(0, i, 1, 1);
printf("%d\n", res);
}
return 0;
}
(3) #include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int T, m, n;
int nums[maxn];
inline bool legal(int step, int start, int choice){
if(choice == 2)
return (nums[n - 1] - nums[start]) >= step;
if(n - start < choice) return false;
if(nums[start + 1] - nums[start] >= step)
return legal(step, start + 1, choice - 1);
int left = start + 1;
int right = n - 1;
while(right - left > 1){
int mid = (left + right) / 2;
if(nums[mid] - nums[start] >= step)
right = mid;
else
left = mid;
}
return legal(step, right, choice - 1);
}
int main(){
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", nums + i);
sort(nums, nums + n);
int step_legal = 0;
int step_illegal = nums[n-1] - nums[0] + 1;
while(step_illegal - step_legal > 1){
int mid = (step_illegal + step_legal) / 2;
if(legal(mid, 0, m))
step_legal = mid;
else
step_illegal = mid;
}
printf("%d\n", step_legal);
}
return 0;
}
查看原帖
点赞 2
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 评论 收藏
分享
04-21 21:01
广东工业大学 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 聊聊这家公司值得去吗 #
231072次浏览 2175人参与
# 职场人,说说你的烦心事 #
8333次浏览 69人参与
# 你认为哪个岗位找工作最卷 #
10310次浏览 39人参与
# 职场上哪些事情令人讨厌 #
16548次浏览 82人参与
# 一人一个landing小技巧 #
78308次浏览 1117人参与
# kpi面有什么特征 #
30741次浏览 181人参与
# 秋招最大的收获是什么? #
33796次浏览 296人参与
# 大家每天通勤多久? #
41893次浏览 329人参与
# 职场吐槽大会 #
204974次浏览 1634人参与
# 职场破防瞬间 #
234811次浏览 2125人参与
# 小红书求职进展汇总 #
56028次浏览 483人参与
# 为了找工作你投递了多少公司? #
8614次浏览 112人参与
# 找工作前vs找工作后的心路变化 #
9552次浏览 102人参与
# tplink提前批进度交流 #
162602次浏览 1377人参与
# 通信硬件牛牛的实习日记 #
7102次浏览 65人参与
# 总结:哪家公司面试体验感最好 #
47525次浏览 336人参与
# 机械制造岗投递时间线 #
22665次浏览 345人参与
# 硬件人你反向读研了吗 #
41719次浏览 630人参与
# 许愿池 #
283035次浏览 2868人参与
# 担心入职之后被发现很菜怎么办 #
126223次浏览 753人参与