Atcoder AGC 019 A,B
A - Ice Tea Store
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You've come to your favorite store Infinitesco to buy some ice tea.
The store sells ice tea in bottles of different volumes at different costs. Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen. The store has an infinite supply of bottles of each type.
You want to buy exactly N liters of ice tea. How many yen do you have to spend?
Constraints
- 1≤Q,H,S,D≤108
- 1≤N≤109
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Q H S D
N
Output
Print the smallest number of yen you have to spend to buy exactly N liters of ice tea.
Sample Input 1
20 30 70 90
3
Sample Output 1
150
Buy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90+30+30=150 yen.
Sample Input 2
10000 1000 100 10
1
Sample Output 2
100
Even though a 2-liter bottle costs just 10 yen, you need only 1 liter. Thus, you have to buy a 1-liter bottle for 100 yen.
Sample Input 3
10 100 1000 10000
1
Sample Output 3
40
Now it's better to buy four 0.25-liter bottles for 10+10+10+10=40 yen.
Sample Input 4
12345678 87654321 12345678 87654321
123456789
Sample Output 4
1524157763907942
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[],n;
int main()
{
while(scanf("%lld%lld%lld%lld",&a[],&a[],&a[],&a[])!=EOF)
{
scanf("%lld",&n);
for(int i=;i<;i++) a[i]=min(a[i],*a[i-]);
printf("%lld\n",n/*a[]+(n&)*a[]);
}
return ;
}
B - Reverse and Compare
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
You have a string A=A1A2…An consisting of lowercase English letters.
You can choose any two indices i and j such that 1≤i≤j≤n and reverse substring AiAi+1…Aj.
You can perform this operation at most once.
How many different strings can you obtain?
Constraints
- 1≤|A|≤200,000
- A consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
A
Output
Print the number of different strings you can obtain by reversing any substring in A at most once.
Sample Input 1
aatt
Sample Output 1
5
You can obtain aatt
(don't do anything), atat
(reverse A[2..3]), atta
(reverse A[2..4]), ttaa
(reverse A[1..4]) and taat
(reverse A[1..3]).
Sample Input 2
xxxxxxxxxx
Sample Output 2
1
Whatever substring you reverse, you'll always get xxxxxxxxxx
.
Sample Input 3
abracadabra
Sample Output 3
44
预处理。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[][],ans;
char s[];
int main()
{
while(scanf("%s",s+)!=EOF)
{
memset(a,,sizeof(a));
int len=strlen(s+);
ans=;
for(int i=;i<=len;i++)
{
for(int j=;j<;j++)
a[i][j]=a[i-][j];
a[i][s[i]-'a']++;
}
for(int i=;i<=len;i++)
ans+=len-i-a[len][s[i]-'a']+a[i][s[i]-'a'];
printf("%lld\n",ans+);
}
return ;
}
Atcoder AGC 019 A,B的更多相关文章
- 【做题记录】AtCoder AGC做题记录
做一下AtCoder的AGC锻炼一下思维吧 目前已做题数: 75 总共题数: 239 每一场比赛后面的字母是做完的题,括号里是写完题解的题 AGC001: ABCDEF (DEF) AGC002: A ...
- AtCoder AGC #2 Virtual Participation
在知乎上听zzx大佬说AGC练智商...于是试了一下 A.Range Product 给$a$,$b$,求$\prod^{b}_{i=a}i$是正数,负数还是$0$ ...不写了 B.Box and ...
- 【题解】Atcoder AGC#16 E-Poor Turkeys
%拜!颜神怒A此题,像我这样的渣渣只能看看题解度日╭(╯^╰)╮在这里把两种做法都记录一下吧~ 题解做法:可以考虑单独的一只鸡 u 能否存活.首先我们将 u 加入到集合S.然后我们按照时间倒序往回推, ...
- 【题解】Atcoder AGC#01 E-BBQ Hard
计数题萌萌哒~ 这道题其实就是统计 \(\sum_{i=1}^{n}\sum_{j=i+1}^{n}C\binom{a[i] + a[j]}{a[i] + a[j] + b[i] + b[j]}\) ...
- 【题解】Atcoder AGC#03 E-Sequential operations on Sequence
仙题膜拜系列...首先我们可以发现:如果在截取了一段大的区间之后再截取一段小的区间,显然是没有什么用的.所以我们可以将操作序列变成单调递增的序列. 然后怎么考虑呢?启示:不一定要考虑每一个数字出现的次 ...
- AtCoder AGC #4 Virtual Participation
我好懒啊QAQ 老规矩 从C开始 C.给一个矩阵,里面有一些紫色方块,你需要涂两个矩阵,一个红色,一个蓝色,保证你涂的颜色四连通 然后把红色蓝色矩阵叠起来要求紫色的地方必须是紫色,其他地方不能是紫色 ...
- AtCoder AGC #3 Virtual Participation
Havana真好听qwq AB题就不写了 SB C.BBuBBBlesort! 有一个长度为$n$的数列 你每次可以用两种操作 1.交换两个相邻元素 2.交换两个隔且仅隔了一个的元素 求把数列排成有序 ...
- [题解] Atcoder AGC 005 F Many Easy Problems NTT,组合数学
题目 观察当k固定时答案是什么.先假设每个节点对答案的贡献都是\(\binom{n}{k}\),然后再减掉某个点没有贡献的选点方案数.对于一个节点i,它没有贡献的方案数显然就是所有k个节点都选在i连出 ...
- AtCoder Beginner Contest 122 D - We Like AGC (DP)
D - We Like AGC Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Yo ...
随机推荐
- Chromium Graphics: Compositor Thread Architecture
Compositor Thread Architecture <jamesr, enne, vangelis, nduca> @chromium.org Goals The main re ...
- Linux企业运维人员最常用150个命令汇
近来老男孩发现新手学习Linux记不住命令,不会分类.不会筛选重点,胡子眉毛一把抓当然记不住了. 特别整理Linux运维最常用150个命令和大家分享,大家学习命令不用在盲目了,根据分类,然后逐步学习! ...
- [国家集训队]拉拉队排练 Manancher_前缀和_快速幂
Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace st ...
- vue中使用console.log无效
webpack开发环境下,在vue中使用console.log无效,一直以为webpack出了问题. 使用window.console.log()就能够顺利在浏览器控制台输出了. 以及 在axios请 ...
- 题解 BZOJ4919 【大根堆】
题面:传送门. 老师说今天要考一道线段树合并,然后...然后这道题我就GG了.(当然可以用线段树合并写,只是比较复杂) 有人赛时想了个贪心,然后被机房巨佬hack了,结果在hack的过程中巨佬想出了正 ...
- Log4j2打印一行日志时返回本行日志的字符串
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.impl.Log4jLogEvent; impo ...
- struts2怎么返回一个字符串给jsp?(使用json)
我们都知道使用servlet时可以直接用PrintWriter对象的print方法来向页面传送一些字符串(可以是html标签和内容),然后在用RequestDispatcher来转向网页 虽Strut ...
- KM HDU 3718
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...
- Pocket英语语法---一、形容词性物主代词和名词性物主代词
Pocket英语语法---一.形容词性物主代词和名词性物主代词 一.总结 一句话总结:名词性物主代词=形容词性物主代词+名词 Is that your umbrella? This is your c ...
- php实现简单算法2
php实现简单算法2 去弄php手册,里面有数据结构,有数据结构就好办了,我的算法基础那么好. 而且的话有数据结构的话再配合我脑中的那些算法了,我就都ok啦. 在手册里面搜索php数据结构就好 路径如 ...