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. 写 Java 这么久了,来编译个 JDK 玩玩儿吧

    你每天写的 Java 代码都需要 JDK 的支持,都要跑在 JVM 上,难道你就不好奇 JDK 长什么样子吗.好奇,就来编译并实现一个自己的 JDK 吧. 本次编译环境 macOS 10.12,编译的 ...

  2. 不只是安装,Kolla 让 OpenStack 运维变简单

    使用 kolla 部署的 OpenStack 环境和传统直接安装的环境相比较,因为使用了全容器化部署,基本操作上有很大不同.对于初学者,操作变得更清晰和更简单了,但是如果你已经有了一定的经验,可能反而 ...

  3. JVM之对象

    几乎所有对象都是在堆中分配内存的,这次来讲讲java的对象. 对象的创建主要分为以下几步: 首先,查看类是否装载.当JVM读取到new指令的时候,会拿着符号描述去方法区寻找它所属的类,如果未查找到,则 ...

  4. Idea 注册方式,亲测可用

    参考:https://www.cnblogs.com/aacoutlook/p/9036299.html 2018年3月 <License server>方式不能使用了,只好尝试<A ...

  5. Sql Server学习笔记

    1.指定路径创建数据库 create database student on--创建库的时候必须写 ( name=student, filename='E:\database\student.mdf' ...

  6. 原生javascript实现选项卡(基础版)

    一.实现原理 1.主要运用“排他思想”,在设置当前元素前,先把相应元素恢复到默认状态 2.给相应元素添加下标的应用 二.代码展示 <!DOCTYPE html> <html> ...

  7. cogs 2450. 距离 树链剖分求LCA最近公共祖先 快速求树上两点距离 详细讲解 带注释!

    2450. 距离 ★★   输入文件:distance.in   输出文件:distance.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 在一个村子里有N个房子,一 ...

  8. 谈谈Java的Collection接口

    目录 谈谈Collection 前言 Collection 方法 1.boolean add(E) 2.void clear() 3.boolean contains(Object o) 4.bool ...

  9. flink编译支持CDH6.2.0(hadoop3.0.0)

    准备工作 因为在编译时需要下载许多依赖包,在执行编译前最好先配置下代理仓库 <mirrors> <mirror> <id>nexus-aliyun</id&g ...

  10. Java.数据结构.集合体系详解

    I. 第一部分:常见数据结构 首先简单说下数据结构. 什么是数据结构?数据结构就是组织数据的方式. 常见的数据结构:栈,堆,树,图,数组,队列,链表. 这里主要介绍与java集合体系相关的栈.数组和链 ...