lanqiao 1457 杨辉三角形(朴素解法)
This commit is contained in:
28
12lanqiao/test8-1.cpp
Normal file
28
12lanqiao/test8-1.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// lanqiao 1457 杨辉三角形(朴素解法)
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define int long long
|
||||
const int N = 1e3 + 10;
|
||||
int a[N][N];
|
||||
signed main(){
|
||||
int n; cin >>n;
|
||||
if(n == 1){
|
||||
cout << 1 << endl;
|
||||
return 0;
|
||||
}
|
||||
a[1][1] = a[2][1] = a[2][2] = 1;
|
||||
for(int i = 3; i <= N-1; i++){
|
||||
for(int j = 1; j <= i; j++){
|
||||
if(j == 1 || j == i) a[i][j] = 1;
|
||||
else a[i][j] = a[i-1][j] + a[i-1][j-1];
|
||||
if(a[i][j] == n){ // 1 + 2 + ... + i-1
|
||||
cout << i*(i-1)/2 + j << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* test samples -> 13
|
||||
6
|
||||
*/
|
||||
Reference in New Issue
Block a user