快手 笔试

我太菜了。。。快手前3道编程题不到20分钟就写完了。。第四题愣是花了一个小时写不出来,样例百分百,可能是没看懂题目吧😥😥😥😥#快手##吐槽#
全部评论
第四题并查集加个dp过了
2 回复 分享
发布于 2019-08-25 18:50
第一题比较字符串、第二题类似于数字每一位数求和吧。。第三题,就是循环一下数组....真的是特别简单的那种。。。。。。第四题没看懂,并查集 背包 写出来过不了
1 回复 分享
发布于 2019-08-25 18:36
作者:ASCII128 链接:https://www.nowcoder.com/discuss/233389?type=post&order=time&pos=&page=1 来源:牛客网 #include<bits/stdc++.h> using namespace std; const int mod = 1e9+7; struct node {     int to;     int c;     node(int _to,int _c):to(_to),c(_c){} }; struct node2 {     int to;     int c;     int num;      node2(int _to,int _c,int _num):to(_to),c(_c),num(_num){} }; vector<node>g[100010]; vector<node2>G[100010]; bool vis[100010]; void build(int root){     if(vis[root]==1) return;     vis[root]=1;     for(int i=0;i<g[root].size();i++){         if(vis[g[root][i].to]==0){             G[root].push_back(node2(g[root][i].to,g[root][i].c,0));             build(g[root][i].to);         }     } } int num[100010],ans=0; int fast(int a,int b) {     int ans=1;     while(b)     {         if(b%2==1) ans=1LL*ans*a%mod;         b/=2;         a=1LL*a*a%mod;     }     return ans; } int n,k,l,r,c; void solve(int root) {     num[root]=1;     for(int i=0;i<G[root].size();i++){         solve(G[root][i].to);         if(G[root][i].c==0) {                 num[root]+=num[G[root][i].to];                 ans=(ans+mod-fast(num[G[root][i].to],k))%mod;         }     }     ans=(ans+fast(num[root],k))%mod; } int main() {     memset(vis,0,sizeof(vis));     memset(num,0,sizeof(num));     cin>>n>>k;     for(int i=0;i<n-1;i++){         scanf("%d %d %d",&l,&r,&c);         g[l].push_back(node(r,c));         g[r].push_back(node(l,c));     }     build(1);     solve(1);     cout<<(fast(n,k)+mod-ans)%mod<<endl; } 🤣大佬分享的AC代码
点赞 回复 分享
发布于 2019-08-25 18:52
主要就是获取黑边分割的区域
点赞 回复 分享
发布于 2019-08-25 18:44
是算法A卷吗
点赞 回复 分享
发布于 2019-08-25 18:35
虽然结果和大佬一样,但是我是做完前三题就没时间做剩下的了
点赞 回复 分享
发布于 2019-08-25 18:33
前三道20分不到可以写完吗?
点赞 回复 分享
发布于 2019-08-25 18:33
楼主 前三道编程是什么内容呢
点赞 回复 分享
发布于 2019-08-25 18:32

相关推荐

评论
点赞
4
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务