迅雷后台开发编程题

1题 积木和
int main(){
int x,y;
while(cin>>x>>y){
int maxx = INT_MIN;
int num = 0;
for(int i = 0;i<=7;i++){
int temp = x*i+y*(7-i);
if(temp>=maxx&&temp<0){
maxx = temp;
num = i;
}
}
cout<<maxx*2+x*(num>=3?3:num)+y*(num>=3?0:3-num)<<endl;
}
system("pause");
return 0;
}

2素勾股数
int res(int a,int b){
int x = a>b?a:b;
int y = a<=b?a:b;
while(x%y!=0){
int temp = y;
y = x%y;
x = temp;
}
return y;
}
struct pt{
int x;
int y;
int z;
pt(int a,int b,int c):x(a),y(b),z(c){}
pt();
};
int main(){
int n;
while(cin>>n){
vector<pt> vec;
int count = 0;
for(int i = 1;i<=n;i++){
for(int j = i;j<=n;j++){
int c = sqrt((double)i*i+j*j);
if(c*c == i*i+j*j&&c<=n){
int d = res(i,j);
pt p(i/d,j/d,c/d);
bool flg = true;
for(int i = 0;i<vec.size();i++){
if(vec[i].x==p.x&&vec[i].y==p.y&&vec[i].z==p.z){
flg = false;
break;
}
}
if(flg&&res(i/d,j/d)==1&&res(i/d,c/d)==1&&res(j/d,c/d)==1){
count++;
vec.push_back(p);
}
}
}
}
cout<<count<<endl;
}
return 0;
}

#迅雷##笔试题目#
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-18 16:32
quench@0916:一顿操作猛如虎,一看工资2500
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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