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的更多相关文章
随机推荐
- 文档对象DOM的操作及使用
Dom对象是什么? DOM对象就是每次你打开浏览器后,进入一个网址时浏览器获取到的HTML文本内容,当浏览器获取到HTML文本内容时,会将其内容以DOM对象的形式缓存到内存中,这时你便可以对DOM对象 ...
- 【一起学源码-微服务】Feign 源码三:Feign结合Ribbon实现负载均衡的原理分析
前言 前情回顾 上一讲我们已经知道了Feign的工作原理其实是在项目启动的时候,通过JDK动态代理为每个FeignClinent生成一个动态代理. 动态代理的数据结构是:ReflectiveFeign ...
- C# 获取WebBrowser内容的高度
int webHeight =0; WebBrowser web =new WebBrowser(); web.Navigate("about:blank"); while (we ...
- 【转】Java实现折半查找(二分查找)的递归和非递归算法
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://wintys.blog.51cto.com/425414/94051 Java二分 ...
- pqsql 防注入
在数据库查询时经常会遇到根据传入的参数查询内容的情况,传入的参数有可能会带有恶意代码,比如or 1=1,这样where判断为true,就会返还所有的记录.为了解决这个问题,可以在参数外面包一层单引号, ...
- 你的应用安全吗? ——用Xray和Synk保驾护航
一.背景 在当下软件应用的开发过程当中,自研的内部代码所占的比例逐步地减少,开源的框架和共用库已经得到了广泛的引用.如下图所示,在一个Kubernetes部署的应用当中,我们自己开发代码所占的比例可能 ...
- AESEncryption Aes 加密
/******************************************************* * * 作者:朱皖苏 * 创建日期:20180521 * 说明:此文件只包含一个类,具 ...
- 从Main读取appsetting
using System; using System.Configuration; using Newtonsoft.Json.Linq; using System.Net.Http; using S ...
- struts2 convention插件
1.struts2自2.1以后推荐使用Convention Plugin支持struts零配置支持(引入jar:struts2-convention-plugin-2.x.x.jar)①convent ...
- python的logging模块使用方法
logging模块 logging模块是Python内置的日志模块,用来生成程序的日志.一条日志对应一个事件的发生,一个事件一般包括:事件发生时间.事件发生位置.事件内容.事件严重程度-日志级别.(还 ...