ABC 210
A
按题意模拟。
scanf("%lld%lld%lld%lld",&n,&a,&x,&y);
std::cout<<n * x - (x - y) * std::max(n - a,0ll);
B
判断第一个 \(1\) 的位置的奇偶性。
scanf("%lld",&n);
scanf("%s",a + 1);
for(int i = 1;i <= n;++i){
if(a[i] == '1'){
if(i % 2)
puts("Takahashi");
else
puts("Aoki");
return 0;
}
}
C
用 \(map\) 记录每个 \(k\) 长度区间的每个颜色的出现情况。
每次向右移一位,则把前者移除,后者加入。
scanf("%lld%lld",&n,&k);
for(int i = 1;i <= n;++i){
scanf("%lld",&c[i]);
}
ll now = 0,ans = 0;
for(int i = 1;i <= k;++i){
QWQ[c[i]] ++ ;
if(QWQ[c[i]] == 1)
now ++ ;
}
ans = now;
for(int i = k + 1;i <= n;++i){
QWQ[c[i - k]] -- ;
if(QWQ[c[i - k]] == 0)
now -- ;
QWQ[c[i]] ++ ;
if(QWQ[c[i]] == 1)
now ++ ;
ans = std::max(now,ans);
}
std::cout<<ans<<std::endl;
D
考虑先考虑行的贡献,先把 \(a_{i,j} \to a_{i,j} + i * c\) ,并预处理出每行每列下的最小值。
然后我们按列按行枚举,在枚举第 \(i\) 列时,先把对应的行下的最小值区间,把 \([1,i]\) 加 \(c\),\([i + 1,n]\) 减 \(c\) ,可以使用线段树维护,然后查询最小值就好了。
同时要考虑在同行的操作,复杂度 \(O(nlogn)\) 。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define ll long long
#define N 1005
#define lowbit(x) (x & -x)
ll a[N][N],k[N][N],pre[N][N],s[N][N];
ll h,w,c;
struct P{
ll v,tag;
P(){v = tag = 0;}
};
struct segment{
P t[N << 2];
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define mid ((l + r) >> 1)
inline void up(int u){
t[u].v = std::min(t[ls(u)].v,t[rs(u)].v);
}
inline void push_down(int u){
if(t[u].tag){
t[ls(u)].v += t[u].tag;
t[ls(u)].tag += t[u].tag;
t[rs(u)].v += t[u].tag;
t[rs(u)].tag += t[u].tag;
t[u].tag = 0;
}
}
inline void add(int u,int l,int r,int tl,int tr,ll p){
if(tl <= l && r <= tr){
t[u].v += p;
t[u].tag += p;
return ;
}
push_down(u);
if(tl <= mid)
add(ls(u),l,mid,tl,tr,p);
if(tr > mid)
add(rs(u),mid + 1,r,tl,tr,p);
up(u);
}
}e[N];
ll ans = 9e18;
ll f[N];
int main(){
scanf("%lld%lld%lld",&h,&w,&c);
for(int i = 1;i <= h;++i)
for(int j = 1;j <= w;++j)
scanf("%lld",&a[i][j]),k[i][j] = a[i][j];
for(int i = 1;i <= h;++i)
for(int j = 1;j <= w;++j)
k[i][j] += i * c;
// for(int i = 1;i <= h;++i,puts(""))
// for(int j = 1;j <= w;++j)
// std::cout<<k[i][j]<<" ";
for(int i = 1;i <= w;++i)
for(int j = h;j >= 1;--j){
if(j == h)continue;
k[j][i] = std::min(k[j + 1][i],k[j][i]);
}
for(int i = 1;i <= h;++i)
for(int j = 1;j <= w;++j)
k[i][j] += (j - 1)*c;
// for(int i = 1;i <= h;++i,puts(""))
// for(int j = 1;j <= w;++j)
// std::cout<<k[i][j]<<" ";
// puts("");
for(int i = 1;i <= h;++i)
for(int j = 1;j <= w;++j)
e[i].add(1,1,w,j,j,k[i][j]);
// for(int j = 1;j <= w;++j)
// for(int i = 1;i <= h;++i)
// std::cout<<e[i].t[1].v<<std::endl;
for(int i = 1;i <= h - 1;++i)
ans = std::min(ans,1ll * e[i + 1].t[1].v + a[i][1] - i * c);
for(int i = 2;i <= w;++i)
for(int j = 1;j <= h - 1;++j){
e[j + 1].add(1,1,w,1,i - 1,c);
e[j + 1].add(1,1,w,i,w,-c);
ans = std::min(ans,1ll * e[j + 1].t[1].v + a[j][i] - j * c);
}
for(int i = 1;i <= h;++i){
std::memset(f,0x7f,sizeof(f));
for(int j = 1;j <= w;++j){
if(j != 1)
f[j] = f[j - 1] + c;
ans = std::min(ans,f[j] + a[i][j]);
f[j] = std::min(f[j],a[i][j]);
}
}
std::cout<<ans<<std::endl;
}
F
维护循环节就好。
按代价排序,并维护循环节至 \(1\) 。
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
pii a[100005];
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
signed main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (register int i = 1; i <= m; i++) cin >> a[i].second >> a[i].first;
sort(a + 1, a + m + 1);
int answer = 0;
for (register int i = 1; n > 1 && i <= m; i++) {
int tn = gcd(n, a[i].second);
answer += (n - tn) * a[i].first;
n = tn;
}
if (n > 1)
cout << -1 << endl;
else
cout << answer << endl;
return 0;
}
ABC 210的更多相关文章
- 算法竞赛入门经典 习题2-10 排列(permutation)
习题2-10 排列(permutation) 用1,2,3,-,9组成3个三位数 abc, def, 和ghi,每个数字恰好使用一次,要求 abc:def:ghi = 1:2:3.输出所有解.提示:不 ...
- 算法竞赛入门经典 习题 2-10 排列(permutation)
习题 2-10 用1,2,3.....,9组成3个三位数abc.def和ghi,每一个数字恰好使用一次,要求abc:def:ghi=1:2:3.输出全部解. #include <stdio.h& ...
- 【IOS】将一组包含中文的数据按照#ABC...Z✿分组
上一篇文章[IOS]模仿windowsphone列表索引控件YFMetroListBox里面 我们一步步的实现了WindowsPhone风格的索引. 但是有没有发现,如果你要实现按照字母排序,你还得自 ...
- 在JS中关于堆与栈的认识function abc(a){ a=100; } function abc2(arr){ arr[0]=0; }
平常我们的印象中堆与栈就是两种数据结构,栈就是先进后出:堆就是先进先出.下面我就常见的例子做分析: main.cpp int a = 0; 全局初始化区 char *p1; 全局未初始化区 main( ...
- 学习Python的ABC模块(转)
http://yansu.org/2013/06/09/learn-Python-abc-module.html 1.abc模块作用 Python本身不提供抽象类和接口机制,要想实现抽象类,可以借助a ...
- 将abc的全排列输出
#include "iostream" using namespace std; void swap(char a[],int i,int j){ char temp; temp= ...
- 关于String str =new String("abc")和 String str = "abc"的比较
String是一个非常常用的类,应该深入的去了解String 如: String str =new String("abc") String str1 = "abc&qu ...
- IE9 使用document.getElementsByName("abc") 不能获取到名称相同SPAN元素
<div name="abc"></div> <input name="abc" type="text" /& ...
- 经典String str = new String("abc")内存分配问题
出自:http://blog.csdn.net/ycwload/article/details/2650059 今天要找和存储管理相关的一些知识,网上搜了半天也没有找到完善的(30%的程度都不到),没 ...
随机推荐
- Bubble和BubbleButton气泡框
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.lang.builder import Buil ...
- mybatis学习笔记(1)基本环境
1.pom引入 <dependencies> <dependency> <groupId>org.mybatis</groupId> <artif ...
- 『学了就忘』Linux基础 — 6、VMware虚拟机安装Linux系统(超详细)
目录 1.打开VMware虚拟机软件 2.选择Linux系统的ISO安装镜像 3.开启虚拟机安装系统 (1)进入Linux系统安装界面 (2)硬件检测 (3)检测光盘 (4)欢迎界面 (5)选择语言 ...
- best-time-to-buy-and-sell-stock-iii leetcode C++
Say you have an array for which the i th element is the price of a given stock on day i. Design an a ...
- Obsidian中使用Calendar插件快捷建立日记、周记
Calendar插件 Calendar插件是我第一个安装使用的插件,插件可以帮助我们很便捷的记录每天的工作 插件效果图 插件下载 下载地址 插件安装 # Obsidian如何手动下载并安装插件-以看板 ...
- QuantumTunnel:内网穿透服务设计
背景 最近工作中有公网访问内网服务的需求,便了解了内网穿透相关的知识.发现原理和实现都不复杂,遂产生了设计一个内网穿透的想法. 名字想好了,就叫QuantumTunnel,量子隧道,名字来源于量子纠缠 ...
- [源码解析] PyTorch 如何使用GPU
[源码解析] PyTorch 如何使用GPU 目录 [源码解析] PyTorch 如何使用GPU 0x00 摘要 0x01 问题 0x02 移动模型到GPU 2.1 cuda 操作 2.2 Modul ...
- MySQL:由于找不到VCRUNTIME140_1.dll,无法继续执行代码。重新安装程序可能会解决此问题
我只是搬用工,记录一下 方法一: 安装这个微软常用运行库合集(https://www.repaik.com/), 链接:https://pan.baidu.com/s/1r4JJaUKjw-y1g3l ...
- #web开发# 知道cookie hostonly属性的请举手。
Cookie常见姿势.疑难梳理 目前w3c定义浏览器存放每个cookie需要包含以下字段: cookie属性 基本描述 举例 备注 name=value cookie键值对 id=a3fWa expi ...
- 2021 羊城杯WriteUP
比赛感受 题目质量挺不错的,不知道题目会不会上buu有机会复现一下,躺了个三等奖,发下队伍的wp Team BinX from GZHU web Checkin_Go 源码下载下来发现是go语言写的 ...