2017网易有道校招三道编程题
来源:互联网 发布:微信淘客助手群发软件 编辑:程序博客网 时间:2024/06/06 03:34
2017网易校招三道编程题(较简单,三道均100%AC)
1.数字与数位问题
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
给出一个非负整数,在[0, 10^n)范围内统计各个数位上的数字均不同的整数个数。
举个例子:
当n=2,答案为91,排除掉{11,22,33,44,55,66,77,88,99}
输入
输入一个非负整数n
输出
输出各个数位上的数字均不同的整数个数
样例输入
1
样例输出
10
#include<iostream>#include<algorithm>#include<vector>#include<set>using namespace std;bool isDiff(int n){ int i=n; set<int> seti; while(i){ int mod = i%10; if(seti.count(mod))return false; else seti.insert(mod); i = i/10; } return true;}int getNum(int n){ long long max = pow(10,n); int num=0; for(int i=0;i<max;++i){ if(isDiff(i))num++; } return num; }int main(){ int n; cin>>n; cout<<getNum(n)<<endl; return 0;}
2.行李箱问题
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
公司准备去旅游了, 我有一个限定载重为m KG的行李箱, 而我有n个物品,
假如每个物品的重量为a[i] KG, 那么我这个行李箱在不超过限定载重的情况下,最多能装多少KG;
输入
第一行输入限定载重,第二行输入每个物品的重量
输出
最多能装的重量
样例输入
11
2 3 5 7
样例输出
10
#include<iostream>#include<algorithm>#include<vector>using namespace std;void _getMaxHeight(const vector<int> &ves,int i,int end,int &max,int m,int now){ if(i>end){ if(max<now)max = now; return; } else{ _getMaxHeight(ves,i+1,end,max,m,now); if(now+ves[i]<=m){ _getMaxHeight(ves,i+1,end,max,m,now+ves[i]); } }}int getMaxHeight(){ int m; vector<int> ves; cin>>m; int tmp; while(cin>>tmp) ves.push_back(tmp); int maxHeight=0,now=0; int end = ves.size()-1; _getMaxHeight(ves,0,end,maxHeight,m,now); return maxHeight;}int main(){ cout<<getMaxHeight()<<endl; return 0;}
3.查找对称轴
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
给定二维平面上的n个点,问是否存在一条平行于y轴的直线,使得这n个点相对于这条直线对称。
输入
每一行表示二维平面上一个点,横坐标与纵坐标用空格隔开
输出
若存在平行于y轴的直线,输出true。否则输出false
样例输入
1 0
-1 0
样例输出
true
#include<iostream>#include<algorithm>#include<vector>using namespace std;typedef struct point{ double x,y; point(double _x,double _y):x(_x),y(_y){}}P;bool comparePointLeft(point a,point b){ if(a.x==b.x)return a.y<b.y; else return a.x<b.x;}bool comparePointRight(point a,point b){ if(a.x==b.x)return a.y>b.y; else return a.x<b.x;}bool isExistLine(){ double x,y; vector<point> vesp; while(cin>>x>>y){ point tmp(x,y); vesp.push_back(tmp); } sort(vesp.begin(),vesp.end(),comparePointLeft); int num = vesp.size(); sort(vesp.begin()+num/2,vesp.end(),comparePointRight); double length = vesp[0].x+vesp[num-1].x; double mid = length*1.0/2; int left,right; if(num<=1)return true; if(num%2==0){ left = num/2-1; right = num/2; } else{ left = num/2-1; right = num/2+1; double tmp = vesp[num/2].x; if(tmp!=mid)return false; } while(left>=0){ if((vesp[left].x+vesp[right].x)!=length||vesp[left].y!=vesp[right].y)return false; --left; ++right; } return true; }int main(){ if(isExistLine())cout<<"true"<<endl; else cout<<"false"<<endl; return 0;}
0 0
- 2017网易有道校招三道编程题
- 2017网易有道编程题:构造队列
- 网易有道2017内推编程题
- 网易有道2017内推编程题
- 网易有道2017内推编程题
- 网易有道2017内推编程题
- 网易有道2017内推编程题第一题
- 洗牌-网易有道2017内推编程题
- 构造队列-网易有道2017年内推编程题
- 网易有道2017内推编程题-Java实现
- 网易有道2017内推编程题 洗牌(模拟)
- 网易有道2017内推编程题 构造队列(模拟)
- 2017网易有道内推笔试编程题1:洗牌
- 网易有道2017内推编程题2
- 网易有道2017内推编程题1
- 洗牌----网易有道2017内推编程题还未完成。
- 网易有道2017内推编程题 队列操作(映射)
- 网易有道2017校园招聘编程题——洗牌
- STL空间配置器
- Mark Otto 编写的HTML/CSS代码风格指南
- SQLite数据库存储数据
- poj2049 Finding Nemo(建图+BFS+优先队列+特判)
- html中表单使用总结
- 2017网易有道校招三道编程题
- 数据结构 --- 链表
- DataGrip 学习笔记
- 微信小程序例子——使用video组件播放视频
- 微信小程序例子——使用image组件显示图片
- ScrollView中嵌套ListView滚动效果冲突问题
- collection集合接口子类---set接口
- docker registry intro
- 自定义Toast