题解 | #Hello World for U#

Hello World for U

http://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b

知识点

绘图,模拟,枚举。可以认为是鸡兔同笼的变式题

关键点

And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 2 = N.

要明白,n1=n3,且n1+n2+n3=N+2。那个max说“n1<=n2”。翻译到这个程度,就是鸡兔同笼问题了。
最后的输出难度不大,只要找对了n1,n2,n3就可以了。

代码

```C++
#include <bits stdc++.h>
using namespace std;

int main(){
char s[83];
while(scanf("%s",s)!=EOF){
int length = strlen(s);
int x,y; //x代表n1和n3,y代表n2
int k=0;
int maxY;
//满足y>=3 y<=length 且x<y for(int y="3;y<=length;y++){" x="1;x<=y;x++){" if(2*x+y="=length+2){" if(x>k){
k=x;
maxY = y;
}
}
}
}
x=k;
y=maxY;
//此时x为n1,n3,y为n2 进行输出
//输出x行
for(int i=0;i

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 11:15
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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