Problem A
#include <iostream>
#include <string>
#include <cstdio>
#include <limits.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <unordered_set>
#include <queue>
#include <deque>
using namespace std;
const int N = 1e3+10;
const int M = 1e6;
int main() {
int A, B, C, X;
cin >> A>> B >> C >> X;
if(X <= A) cout<<1<<endl;
else if(X > B) cout<<0<<endl;
else{
printf("%.7lf", C*1.0/(B - A));
}
return 0;
}
Problem B
#include <iostream>
#include <string>
#include <cstdio>
#include <limits.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <unordered_set>
#include <queue>
#include <deque>
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <limits.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <unordered_set>
#include <queue>
#include <deque>
using namespace std;
const int N = 1e3+10;
const int M = 1e6;
int main() {
string s;
cin >>s;
sort(s.begin(), s.end());
cout<<s<<endl;
return 0;
}
Problem C
- 二维动态规划
- 初始的数值只能是1到9,注意边界数值1和9的转移方式。
- 注意数据范围是
long long
#include <iostream>
#include <string>
#include <cstdio>
#include <limits.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <unordered_set>
#include <queue>
#include <deque>
using namespace std;
const int N = 1e3+10;
const int M = 1e6;
constexpr int mod = 998244353;
LL dp[1000010][12];
LL cnt;
int main() {
cin >> n;
memset(dp, 0, sizeof dp);
for(int i = 1; i <= 9; i++) dp[0][i] = 1;
for(int i = 1; i < n; i++) {
for(int j = 1; j <= 9; j++) {
if(j == 1 ) dp[i][j] = (dp[i-1][j] + dp[i-1][j+1]) % mod;
else if(j == 9) dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % mod;
else{
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]) % mod;
}
if(i == n-1) cnt = (cnt + dp[i][j]) % mod;
}
}
cout<<cnt<<endl;
return 0;
}
|