A.小的那个数的阶乘。

#include<bits/stdc++.h>
using namespace std; int a,b; int main()
{
ios::sync_with_stdio();
cin >> a >> b;
int t = min(a,b);
int ans = ;
for(int i = ;i <= t;i++) ans *= i;
cout << ans << endl;
return ;
}

B.暴力t串的起始位置,比较两个串。

#include<bits/stdc++.h>
using namespace std; int n,m;
string s1,s2;
vector<int> v; int main()
{
ios::sync_with_stdio();
cin >> n >> m >> s1 >> s2;
s1 = ' '+s1;
s2 = ' '+s2;
int ans = 1e9;
for(int i = ;i <= m-n;i++)
{
int cnt = ;
for(int j = ;j <= n;j++)
{
if(s1[j] != s2[i+j]) cnt++;
}
if(cnt < ans)
{
ans = cnt;
v.clear();
for(int j = ;j <= n;j++)
{
if(s1[j] != s2[i+j]) v.push_back(j);
}
}
}
cout << ans << endl;
for(int i = ;i < v.size();i++) cout << v[i] << " ";
cout << endl;
return ;
}

C.先按l排序,遍历每一段,维护一个优先队列,每次把当前之前的段从优先队列中拿出来,更新对应长度的最小花费,然后把该段放进优先队列。

#include<bits/stdc++.h>
using namespace std; int n,x;
map<int,int> mp;
struct xx
{
int l,r,c;
friend bool operator <(xx a,xx b)
{
return a.l < b.l;
}
}a[];
struct yy
{
int r,len,c;
yy(int a,int b,int cc):r(a),len(b),c(cc){};
friend bool operator <(yy a,yy b)
{
return a.r > b.r;
}
};
priority_queue<yy> q; int main()
{
ios::sync_with_stdio();
cin >> n >> x;
for(int i = ;i <= n;i++) cin >> a[i].l >> a[i].r >> a[i].c;
sort(a+,a++n);
int ans = 2e9+;
for(int i = ;i <= n;i++)
{
while(!q.empty() && q.top().r < a[i].l)
{
if(!mp.count(q.top().len)) mp[q.top().len] = q.top().c;
else mp[q.top().len] = min(mp[q.top().len],q.top().c);
q.pop();
}
int len = a[i].r-a[i].l+;
if(mp.count(x-len)) ans = min(ans,a[i].c+mp[x-len]);
q.push(yy(a[i].r,len,a[i].c));
}
if(ans == 2e9+) cout << - << endl;
else cout << ans << endl;
return ;
}

D.暴力dp刚好卡过。

#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; int t,l,r;
long long dp[],f[]; int main()
{
ios::sync_with_stdio();
cin >> t >> l >> r;
for(int i = ;i <= r;i++)
{
f[i] = (long long)i*(i-)/;
dp[i] = f[i];
}
for(int i = ;i <= r;i++)
{
for(int j = i,k = ;j <= r;j += i,k++) dp[j] = min(dp[j],dp[i]*k+f[k]);
}
long long tt = ,ans = ;;
for(int i = l;i <= r;i++)
{
ans = (ans+dp[i]%MOD*tt)%MOD;
tt = tt*t%MOD;
}
cout << ans << endl;
return ;
}

E.dp,类似01背包,开两个数组记录两个串中的位置。

#include<bits/stdc++.h>
using namespace std; string s,t;
int n,m,x,a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> s >> m >> t >> x;
s = ' '+s;
t = ' '+t;
for(int i = ;i <= x;i++) a[i] = ;
for(int i = ;i <= n;i++)
{
for(int j = x;j >= ;j--)
{
int now = a[j];
if(i < b[j]) continue;
int k = ;
while(k+now <= m)
{
if(s[i+k] != t[now+k]) break;
k++;
}
if(now+k > m)
{
cout << "YES" << endl;
return ;
}
if(a[j+] < now+k)
{
a[j+] = now+k;
b[j+] = i+k;
}
}
}
cout << "NO" << endl;
return ;
}

Codeforces_822的更多相关文章

随机推荐

  1. 聊聊密码学中的DES算法

    用心分享,共同成长 没有什么比你每天进步一点点更实在了 本文已经收录至我的github,欢迎大家踊跃star 和 issues. https://github.com/midou-tech/artic ...

  2. 大量SQL的解决方案——sdmap

    大量SQL的解决方案--sdmap 最近看到群里面经常讨论大型应用中SQL的管理办法,有人说用EF/EF Core,但很多人不信任它生成SQL的语句:有人说用Dapper,但将SQL写到代码中有些人觉 ...

  3. 学会python正则表达式就是这么简单

    一前言 本篇文章带大家快速入门正则表达式的使用,正则表达式的规则不仅适用python语言,基本大多数编程语言都适用,在日常使用中极为广泛,读者们有必要学好正则表达式.看完这篇文章,读者们要理解什么是正 ...

  4. POJ 3304 Segments(判断直线与线段是否相交)

    题目传送门:POJ 3304 Segments Description Given n segments in the two dimensional space, write a program, ...

  5. 0182 JavaScript执行机制:单线程,同步任务和异步任务,执行栈,消息队列,事件循环

    以下代码执行的结果是什么? [结果是1 2 3 ] console.log(1); setTimeout(function () { console.log(3); }, 1000); console ...

  6. 从头学pytorch(二十):残差网络resnet

    残差网络ResNet resnet是何凯明大神在2015年提出的.并且获得了当年的ImageNet比赛的冠军. 残差网络具有里程碑的意义,为以后的网络设计提出了一个新的思路. googlenet的思路 ...

  7. js css html加载顺序

    1.js放在head中会立即执行,阻塞后续的资源下载与执行.因为js有可能会修改dom,如果不阻塞后续的资源下载,dom的操作顺序不可控.正常的网页加载流程是这样的.浏览器一边下载HTML网页,一边开 ...

  8. 编写自己的 GitHub Action,体验自动化部署

    本文将介绍如何使用 GitHub Actions 部署前端静态页面,以及如何自己创建一个 Docker 容器 Action. 简介 Actions GitHub Actions 是 GitHub 官方 ...

  9. 如何选择kmeans中的k值——肘部法则–Elbow Method和轮廓系数–Silhouette Coefficient

    肘部法则–Elbow Method 我们知道k-means是以最小化样本与质点平方误差作为目标函数,将每个簇的质点与簇内样本点的平方距离误差和称为畸变程度(distortions),那么,对于一个簇, ...

  10. emeditor安装及插件信息

    原文地址:https://www.52pojie.cn/thread-658917-1-1.html 废话不多说 官网:https://www.emeditor.com/download/ 安装版:6 ...