个人题解 |
三角形
https://ac.nowcoder.com/acm/contest/85347/A
略抽象的一场
A.
签到
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define li __int128
#define pll pair<ll,ll>
ll a[200005];
int main(){
map<int,int>mp;
int n;cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
if(mp[a[i]]>=3){
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}
B
签到,容易知道只要没有0就符合
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define li __int128
#define pll pair<ll,ll>
ll a[200005];
int main(){
int n;cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]==0){
cout<<"NO";
return 0;
}
}
cout<<"YES";
return 0;
}
C
首先原数列是正整数树列,意味着其前缀和序列是严格单调上升的,0<si说明si序列不含0;
假设大于0的平方数有x个,显然我们要做的就是从这里面挑n个数字组成一个严格单增的序列,组合数C(x,n)即可
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define li __int128
#define pll pair<ll,ll>
const ll mod=1e9+7;
const int N=1e5+10;
ll f[N],invf[N];
ll pows(ll a,ll n){
ll ans=1;
while(n){
if(n&1) ans=ans*a%mod;
a=a*a%mod;n>>=1;
}
return ans;
}
void init(){
f[1]=1;
invf[1]=pows(f[1],mod-2);
for(int i=2; i<N; i++){
f[i]=f[i-1]*i%mod;invf[i]=pows(f[i],mod-2);
}
}
ll c(ll a,ll b){
if(a==b) return 1;
return f[a]*invf[a-b]%mod*invf[b]%mod;
}
int main(){
init();
ll n,x;cin>>n>>x;
ll rig=0,sum=0;
for(ll i=1;i<=x;i++){
if(i*i<=x){
rig++;
}
}
if(rig<n){
cout<<0<<'\n';
return 0;
}
cout<<c(rig,n);
return 0;
}
D
一个非常重要的思维:b[i]数组是没有用的,对于,无论i怎么取结果都是1
这意味着我们只看a就可以
然后看一眼数据范围,bfs就完了
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define li __int128
#define pll pair<ll,ll>
int dirc[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int bfs(const vector<vector<int>>& maze, int p) {
int n = maze.size();
int m = maze[0].size();
queue<tuple<int, int, int, int>> q;
int steps[n][m][p-1];
memset(steps, -1, sizeof(steps));
q.emplace(0, 0, maze[0][0] % (p - 1), 0);
steps[0][0][maze[0][0] % (p - 1)] = 0;
while (!q.empty()) {
auto [x, y, c, step] = q.front();
q.pop();
if (x == n - 1 && y == m - 1 && c == 0) {
return step;
}
for (auto& dir : dirc) {
int nx = x + dir[0];
int ny = y + dir[1];
if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
int new_c = (c + maze[nx][ny]) % (p - 1);
if (steps[nx][ny][new_c] == -1 || step + 1 < steps[nx][ny][new_c]) {
q.emplace(nx, ny, new_c, step + 1);
steps[nx][ny][new_c] = step + 1;
}
}
}
}
return -1;
}
int main() {
int n, m, p;
cin >> n >> m >> p;
vector<vector<int>> maze(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> maze[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int xxx;
cin >> xxx;
}
}
int res = bfs(maze, p);
if (res == -1) {
cout << "-1";
}
else {
cout << res;
}
return 0;
}