A-国际旅行Ⅰ_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
任意城市都互相可达,输出第k大即可
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n,m,k;
int a[1005];
void sovle(){
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
}
sort(a,a+n);
for(int i=0;i<k;i++){
int x;cin>>x;
cout<<a[x-1]<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
D-A*BBBB_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
很麻烦,我选择把NTT模版偷过来秒了。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define endl '\n'
using uint = unsigned;
const int MOD = 998244353;//NTT模数
int Add(int x, int y) { return (x + y >= MOD) ? x + y - MOD : x + y; }
int Dec(int x, int y) { return (x - y < 0) ? x - y + MOD : x - y; }
int mul(int x, int y) { return 1ll * x * y % MOD; }
uint qp(uint a, int b) { uint res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }
namespace NTT {
int sz;
uint w[2500005], w_mf[2500005];
int mf(int x) { return (1ll * x << 32) / MOD; }
void init(int n) {
for (sz = 2; sz < n; sz <<= 1);
uint pr = qp(3, (MOD - 1) / sz);
w[sz / 2] = 1; w_mf[sz / 2] = mf(1);
for (int i = 1; i < sz / 2; i++) w[sz / 2 + i] = mul(w[sz / 2 + i - 1], pr), w_mf[sz / 2 + i] = mf(w[sz / 2 + i]);
for (int i = sz / 2 - 1; i; i--) w[i] = w[i << 1], w_mf[i] = w_mf[i << 1];
}
void ntt(vector<uint>& A, int L) {
for (int d = L >> 1; d; d >>= 1)
for (int i = 0; i < L; i += (d << 1))
for (int j = 0; j < d; j++) {
uint x = A[i + j] + A[i + d + j];
if (x >= 2 * MOD) x -= 2 * MOD;
ll t = A[i + j] + 2 * MOD - A[i + d + j], q = t * w_mf[d + j] >> 32; int y = t * w[d + j] - q * MOD;
A[i + j] = x; A[i + d + j] = y;
}
for (int i = 0; i < L; i++) if (A[i] >= MOD) A[i] -= MOD;
}
void intt(vector<uint>& A, int L) {
for (int d = 1; d < L; d <<= 1)
for (int i = 0; i < L; i += (d << 1))
for (int j = 0; j < d; j++) {
uint x = A[i + j]; if (x >= 2 * MOD) x -= 2 * MOD;
ll t = A[i + d + j], q = t * w_mf[d + j] >> 32, y = t * w[d + j] - q * MOD;
A[i + j] = x + y; A[i + d + j] = x + 2 * MOD - y;
}
int k = (L & (-L));
reverse(A.begin() + 1, A.end());
for (int i = 0; i < L; i++) {
ll m = -A[i] & (L - 1);
A[i] = (A[i] + m * MOD) / k;
if (A[i] >= MOD) A[i] -= MOD;
}
}
}
struct bigint {
vector<int> nums;
int operator[](const int& k)const { return nums[k]; }
int& operator[](const int& k) { return nums[k]; }
int size() { return nums.size(); }
void push_back(int x) { nums.push_back(x); }
bigint(int x = 0) {
do {
nums.push_back(x % 10);
x /= 10;
} while (x);
}
bigint(string s) {
for (int i = s.size() - 1; i >= 0; i--)
nums.push_back(s[i] - '0');
trim();
}
void trim() {
while (nums.size() > 1 && nums.back() == 0) {
nums.pop_back();
}
}
void clear() {
nums.clear();
}
friend istream& operator>>(istream& cin, bigint& num) {
string tnum;
cin >> tnum;
num = tnum;
return cin;
}
friend ostream& operator<<(ostream& cout, bigint num) {
bool start = false;
for (int i = num.size() - 1; i >= 0; i--) {
if (!start && num[i] == 0)
continue;
start = true;
cout << num[i];
}
if (!start)
cout << 0;
return cout;
}
};
bool operator<(bigint a, bigint b) {
if (a.size() != b.size())
return a.size() < b.size();
for (int i = a.size() - 1; i >= 0; i--)
if (a[i] != b[i])
return a[i] < b[i];
return false;
}
bool operator>(bigint a, bigint b) {
return b < a;
}
bool operator<=(bigint a, bigint b) {
return !(a > b);
}
bool operator>=(bigint a, bigint b) {
return !(a < b);
}
bool operator==(bigint a, bigint b) {
return !(a < b) && !(a > b);
}
bool operator!=(bigint a, bigint b) {
return a < b || a > b;
}
bigint operator+(bigint a, bigint b) {
bigint res;
res.clear();
int t = 0;
int mx = max(a.size(), b.size());
for (int i = 0; i < mx || t; i++) {
if (i < a.size()) {
t += a[i];
}
if (i < b.size()) {
t += b[i];
}
res.push_back(t % 10);
t /= 10;
}
res.trim();
return res;
}
bigint operator-(bigint a, bigint b) {
bigint res(a);
bigint sub(b);
int flag = 0;
int len = res.size();
while (sub.size() < res.size())
sub.push_back(0);
for (int i = 0; i < len; i++) {
if (res[i] + flag >= sub[i]) {
res[i] = res[i] + flag - sub[i];
flag = 0;
}
else {
res[i] = res[i] + 10 + flag - sub[i];
flag = -1;
}
}
res.trim();
return res;
}
// bigint operator*(bigint a, bigint b) {//n^2
// bigint res;
// res.resize(a.size() + b.size(), 0);
// for (int i = 0; i < a.size(); i++) {
// for (int j = 0; j < b.size(); j++) {
// res[i + j] += a[i] * b[j];
// res[i + j + 1] += res[i + j] / 10;
// res[i + j] %= 10;
// }
// }
// res.trim();
// return res;
// }
bigint operator*(bigint a, bigint b) {//nlogn
bigint res;res.nums.pop_back();
int dega = a.size() - 1, degb = b.size() - 1;
int n = dega + degb + 1;
int lim;for (lim = 1; lim < n; lim <<= 1); NTT::init(lim);
vector<uint> A(lim); for (int i = 0;i <= dega;i++) A[i] = a[i];
vector<uint> B(lim);for (int i = 0;i <= degb;i++) B[i] = b[i];
NTT::ntt(A, lim);NTT::ntt(B, lim);
for (int i = 0;i < lim;i++) A[i] = mul(A[i], B[i]);
NTT::intt(A, lim);
for (int i = 0, t = 0;i < lim || t;i++) {
if (i < lim) t += A[i];
res.push_back(t % 10);t /= 10;
}
res.trim();
return res;
}
bigint operator*(bigint a, ll b) {
bigint res(a);
int carry = 0;
for (int i = 0; i < a.size(); i++) {
carry += a[i] * b;
res[i] = carry % 10;
carry /= 10;
}
while (carry > 0) {
res.push_back(carry % 10);
carry /= 10;
}
//res.trim();
return res;
}
bigint operator/(bigint a, bigint b) {
bigint tnum(a);
if (a < b)
return 0;
int n = a.size() - b.size();
b.nums.insert(b.nums.begin(), n, 0);
if (tnum >= b) {
n++;
b.nums.insert(b.nums.begin(), 0);
}
bigint ans;
ans.nums.assign(n, 0);
int n2 = b.size();
while (n--) {
n2--;
b.nums.erase(b.nums.begin());
while (!(tnum < b)) {
int n1 = tnum.size();
for (int j = 0; j < n2; j++) {
tnum[j] -= b[j];
if (tnum[j] < 0) {
tnum[j + 1]--;
tnum[j] += 10;
}
}
tnum.trim();
ans[n]++;
}
}
ans.trim();
return ans;
}
bigint operator/(bigint a, ll b) {
bigint ans;
ans.clear();
int r = 0;
for (int i = a.size() - 1; i >= 0; i--) {
r = r % b * 10 + a[i];
ans.push_back(r / b);
}
reverse(ans.nums.begin(), ans.nums.end());
ans.trim();
return ans;
}
bigint operator%(bigint a, bigint b) {
bigint div_res = a / b;
return a - div_res * b;
}
bigint operator%(bigint a, ll b) {
bigint div_res = a / b;
return a - div_res * b;
}
bigint qp(bigint a, ll n) {
bigint res(1);
while (n) {
if (n & 1) res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
bigint comb(bigint n, bigint m) {
bigint res = 1;
for (bigint up = n, down = 1; down <= m; up = up - 1, down = down + 1)
res = res * up, res = res / down;
return res;
}
//快速comb
void Prework() {
}
void Solve() {
bigint a, b;cin >> a >> b;
cout << a * b << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T = 1;
cin >> T;
Prework();
while (T--) Solve();
}
F-水灵灵的小学弟_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
两个人名字字母一样直接输出
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n,m,k;
int a[N];
void sovle(){
cin>>n>>m;
cout<<"DHY"<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
cin>>t;
while (t--){
sovle();
}
return 0;
}
H-狼狼的备忘录_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
要用一个人和他的信息(全是字符串),可以用map来方便地操作map<string,set<string>>
至于判重,我们可以看如果更优的比差的提前放进去,那么我们对更优的进行操作,把它所有的后缀字串都加入到一个map的set里,这样当更差的输入时直接count找就判掉了。如果差的比优的提前放进去,那么我们就对优的进行后缀查找(substr),当set里有它的后缀,那么就把那个后缀删掉,并插入更优的,结束遍历后还要再插入一次,防止里面没有后缀导致没有进行插入操作而漏掉这个信息,而set保证字符串不会重复。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 3005;
const int mod = 2333;
int n,m,k;
void sovle(){
cin>>n;
map<string,set<string> >q,qq;
for(int i=0;i<n;i++){
string s;
cin>>s>>m;
for(int i=0;i<m;i++){
string d;cin>>d;
if(!qq[s].count(d)){
for(int j=0;j<d.size();j++){
if(q[s].count(d.substr(j))){
q[s].erase(d.substr(j));
q[s].insert(d);
}
}
q[s].insert(d);
for(int j=0;j<d.size();j++){
qq[s].insert(d.substr(j));
}
}
}
}
cout<<q.size()<<endl;
for(auto &[name,se]:q){
cout<<name<<' '<<se.size()<<" ";
for(auto ed:se){
cout<<ed<<' ';
}cout<<endl;
}
}
signed main()
{
//ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
I-重生之zbk要拿回属于他的一切_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
遍历字符串,用substr暴力找
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 66
int i,j,k,n,m,t,res;
string s;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>s;
for(i=0;i<n;i++)if(s.substr(i,5)=="chuan")res++;
cout<<res;
}
J-这是签到_河南萌新联赛2024第(二)场:南阳理工学院 (nowcoder.com)
数据范围小,用行列式计算模版暴力算一遍
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n,m,k;
int aa[15][15];
int det(int n){
int a[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
a[i][j]=aa[i][j];
}
}
int res=1;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
while(a[j][i]){
int t=a[i][i]/a[j][i];
for(int k=i;k<n;k++){
a[i][k]=(a[i][k]-t*a[j][k]);
swap(a[i][k],a[j][k]);
}
res=-res;
}
}
if(!a[i][i]) return 0;
res*=a[i][i];
}
return res;
}
void sovle(){
cin>>n>>m;
int u=max(n,m);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>aa[i][j];
}
}
int min1=INT_MAX;
for(int i=1;i<=u;i++){
//cout<<det(i)<<endl;
min1=min(min1,det(i));
}cout<<min1<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}