当前位置: 代码迷 >> 综合 >> 杭电OJ100题——2050-2054(C++版)
  详细解决方案

杭电OJ100题——2050-2054(C++版)

热度:52   发布时间:2023-12-15 13:34:27.0

折线分割平面

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41525    Accepted Submission(s): 27496


 

Problem Description

我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。

 

 

Input

输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。
 

 

 

Output

对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。
 

 

 

Sample Input

 
 

2 1 2

 

 

Sample Output

 
 

2 7

 

#include<iostream>
using namespace std;int main(){int c;cin>>c;while(c--){int n;cin>>n;long long *arr = new long long[10000];arr[0] = 2;arr[1] = 7;long k = 5;for(int i = 2;i<10000;i++){arr[i] = arr[i-1] + (k+4);k += 4;}cout<<arr[n-1]<<endl;}return 0;
}

Bitset

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 30691    Accepted Submission(s): 22535


 

Problem Description

Give you a number on base ten,you should output it on base two.(0 < n < 1000)

 

 

Input

For each case there is a postive number n on base ten, end of file.

 

 

Output

For each case output a number on base two.

 

 

Sample Input

 
 

1 2 3

 

 

Sample Output

 
 

1 10 11

#include<iostream>
using namespace std;int main(){int n;while(cin>>n){char arr[15];int a_size = 0;do{arr[a_size++] = n%2+'0';n /= 2;}while(n!=0);for(int i = a_size-1;i>0;i--)cout<<arr[i];cout<<arr[0]<<endl;}return 0;
}

Picture

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40391    Accepted Submission(s): 19651


 

Problem Description

Give you the width and height of the rectangle,darw it.

 

 

Input

Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.

 

 

Output

For each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.

 

 

Sample Input

 
 

3 2

 

 

Sample Output

 
 

+---+

|      |

|      |

+---+

#include<stdio.h>
#include<iostream>
using namespace std;int main(){int width,height;while(scanf("%d%d",&width,&height)!=EOF){//输出第一行cout<<"+";for(int i=0;i<width;i++)cout<<"-";cout<<"+"<<endl;//输出高for(int i=0;i<height;i++){cout<<"|";for(int i=0;i<width;i++)cout<<" ";cout<<"|"<<endl;}//输出最后一行cout<<"+";for(int i=0;i<width;i++)cout<<"-";cout<<"+"<<endl;cout<<endl;}
}

Switch Game

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23954    Accepted Submission(s): 14579


 

Problem Description

There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).

 

 

Input

Each test case contains only a number n ( 0< n<= 10^5) in a line.

 

 

Output

Output the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).

 

 

Sample Input

 
 

1 5

 

 

Sample Output

 
 

1 0

#include<iostream>
using namespace std;int main(){int n;while(cin>>n){int result = 0;for(int i=1;i<=n;i++)if(n%i==0){if(result==0)result = 1;elseresult = 0;}cout<<result<<endl;}return 0;
}

A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 135808    Accepted Submission(s): 21674


 

Problem Description

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".

 

 

Input

each test case contains two numbers A and B.

 

 

Output

for each case, if A is equal to B, you should print "YES", or print "NO".

 

 

Sample Input

 
 

1 2

2 2

3 3

4 3

 

 

Sample Output

 
 

NO

YES

YES

NO

#include<iostream>
using namespace std;
#include<string>
void trim0(string& b)
{int len = b.length();//如果是小数就去除末尾的0,如2.0000和2if(b.find('.')!=string::npos){for(int i=len-1;b[i]=='0';i--)len--;b=b.substr(0,len);}if(b[len-1]=='.')b=b.substr(0,len-1);
}
int main()
{string a,b;while(cin>>a>>b){trim0(a);trim0(b);if(a==b)cout<<"YES"<<endl;elsecout<<"NO"<<endl;}
}