[CodeM美团比赛] 优惠券
2017-06-23 23:23
127 查看
题目链接
https://www.nowcoder.com/test/5513596/summary解题思路
http://static.nowcoder.com/b/codem/codem_qulification.zip代码
#include<vector> #include<iostream> #include<algorithm> using namespace std; const int MAXN = 1e5+5; //go从前往后 rg从后往前 vector<int> go[MAXN], rg[MAXN]; int vis[MAXN],OK[MAXN]; vector<int> res; //记录数组 void dfs1(int t) { OK[t]=1; for(int i=0; i<(int)rg[t].size(); ++i) { int v = rg[t][i]; //拿到能到t的第i个节点 if(!OK[v]) { dfs1(v); } } } void dfs2(int s, int t) { if(s == t) { for(int i=0; i<(int)res.size(); ++i) { printf("%c", res[i]+'a'); } exit(0); } vis[s] = 1; for(int i=0; i<(int)go[s].size(); ++i) { int v = go[s][i]; if(v<0 || !OK[v])//v<0说明无路,ok记录经历过的路 continue; if(vis[v]) //环 { printf("Infinity!\n"); exit(0); } res.push_back(i); dfs2(v,t); } } int main() { int n; scanf("%d",&n); for(int i=0; i<2; ++i) for(int j=0; j<n; ++j) { int a; scanf("%d",&a); int t = a+j; if(t>=0 && t<n) { go[j].push_back(t); //从i能走到t rg[t].push_back(j); //t经过i走到的 }else go[j].push_back(-1); } //初始化完成。 dfs1(n-1); if(!OK[0]) { return 0*printf("No solution!\n"); } dfs2(0,n-1); return 0; }
相关文章推荐
- 天池O2O优惠券使用预测比赛--总结
- 天池比赛:o2o优惠券使用预测
- (拓扑排序)HDU 1285 确定比赛名次
- 洛谷2658 汽车拉力比赛 二分
- 蓝桥杯比赛javaB组练习《饮料换购》
- 蓝桥杯比赛javaB组练习《饮料换购》
- USACO历年比赛的数据和解题报告
- 营销系统--优惠券补偿记录
- 5名运动员跳水比赛的名次问题
- 2017华为比赛遗传算法总结
- 一时间脑抽,打了简单的比赛,用用java写点ACM程序,好用不好用就这样了
- 课工场*it课程 看课送课咯 还有优惠券大派送
- hdu 1285 确定比赛名次
- Redis在高并发下常见的错误场景-优惠券列表显示
- java__switch比赛判断
- 一次失败的广告转化率预估比赛
- 百度2016校招:钓鱼比赛 Python
- Kaggle 数据挖掘比赛经验分享 (转载)
- 玲珑杯”ACM比赛 Round #15 D 咸鱼商店【二分+01背包】
- 机器人说:"来,我们比赛垒石头吧~~~"