Codeforces_822
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的更多相关文章
随机推荐
- react路由的跳转和传参
1.路由的跳转 一.DOM跳转 在需要跳转的页面导入import {Link} from 'react-router-dom',在需要跳转的地方使用link标签的to属性进行跳转,路由配置文件中导出的 ...
- html 贪吃蛇代码
最近在搞自己的网站,维护的时候准备放个贪吃蛇上去,顶一下原有的页面. 这个贪吃蛇有一点毒.原来设定了100级:100级刚开局就挂了.后来改掉了选项菜单,修复了. 还有什么bug,欢迎点击侧边的QQ按钮 ...
- js 鼠标位置
1.clientX.clientY 光标位置——>距离当前body可视区域的x,y坐标 2.pageX.pageY 光标位置——> 对于整个页面来说,包括了被卷去的body ...
- JSON小记
json: { "1" : "2", "1" : "3" } 在json中如果有重复的key,会取最后一个key的值,如 ...
- redis订阅发布简单实现
适用场景 业务流程遇到大量异步操作,并且业务不是很复杂 业务的健壮型要求不高 对即时场景要求不高 原理介绍 redis官网文档:https://redis.io/topics/notification ...
- 暑假提高组集训Day1 T1
说实话,今天的题真的有点难! ~备受打击~ 我们先来看一看第一题吧 看起来好像不太简单,其实并不难 下面来提供两种方法吧 1.做法一 //签到题 /* 那么这一题就是告诉你n个点的坐标,把它们分别放到 ...
- Linux删除文件 清除缓存
相信很多测试 经常会经历开发叫你清除缓存这种事. 那我们要怎么清呢? 一.首先,确认你要清除的缓存在哪个目录下,然后切换到该目录下,比如 我现在知道我的的缓存目录是在newerp这个目录下,则如图 二 ...
- SpringCloud之Eureka(注册中心集群篇)(三)
一:集群环境搭建 第一步:我们新建两个注册中心工程一个叫eureka_register_service_master.另外一个叫eureka_register_service_backup eurek ...
- 【原创】Dubbo 2.7.5在线程模型上的优化
这是why技术的第30篇原创文章 这可能是全网第一篇解析Dubbo 2.7.5里程碑版本中的改进点之一:客户端线程模型优化的文章. 先劝退:文本共计8190字,54张图.阅读之前需要对Dubbo相关知 ...
- 异数OS国产CPU平台移植项目需求分析
异数OS国产CPU平台移植项目需求分析 目录 异数OS国产CPU平台移植项目需求分析 项目立项背景 项目需求分析 异数OS性能指标简介 1.TCP协议栈性能测试 2.异数OS-织梦师-水母 消息队列性 ...