Atcoder Regular-074 Writeup
C - Chocolate Bar
题面
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize Smax - Smin, where Smax is the area (the number of blocks contained) of the largest piece, and Smin is the area of the smallest piece. Find the minimum possible value of Smax−Smin.
题意
给你一个矩形,切两刀,问怎么切面积极差最小
直接暴力枚举一下,然后旋转一下。
代码
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll h,w;
ll ans;
ll ans1;
ll ans2;
ll ans3;
ll big;
ll small;
int main()
{
ios::sync_with_stdio(false);
cin>>h>>w;
// if (h%3==0 || w%3==0) return 0*puts("0");
ans=h*w;
for (ll i=1;i<w;i++)
{
big=small=ans1=i*h;
ans2=h/2*(w-i);
ans3=(h+1)/2*(w-i);
big=max(big,ans2);
big=max(big,ans3);
small=min(small,ans2);
small=min(small,ans3);
ans=min(ans,big-small);
}
for (ll i=1;i<w;i++)
{
big=small=ans1=i*h;
ans2=(w-i)/2*h;
ans3=(w-i+1)/2*h;
big=max(big,ans2);
big=max(big,ans3);
small=min(small,ans2);
small=min(small,ans3);
ans=min(ans,big-small);
}
swap(h,w);
for (ll i=1;i<w;i++)
{
big=small=ans1=i*h;
ans2=h/2*(w-i);
ans3=(h+1)/2*(w-i);
big=max(big,ans2);
big=max(big,ans3);
small=min(small,ans2);
small=min(small,ans3);
ans=min(ans,big-small);
}
for (ll i=1;i<w;i++)
{
big=small=ans1=i*h;
ans2=(w-i)/2*h;
ans3=(w-i+1)/2*h;
big=max(big,ans2);
big=max(big,ans3);
small=min(small,ans2);
small=min(small,ans3);
ans=min(ans,big-small);
}
cout<<ans;
}
D - 3N Numbers
题面
Let N be a positive integer.
There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a')−(the sum of the elements in the second half of a').
Find the maximum possible score of a'.
题意
给你长度为3N的序列 求一长度为2N的子序列 使得前面n个减后面n个最大
代码
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int n;
ll a[300010];
ll f[300010];
ll ans;
ll ret;
priority_queue<ll> q;
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for (int i=1;i<=3*n;i++) cin>>a[i];
for (int i=1;i<=n;i++)
{
q.push(-a[i]);
ans+=a[i];
f[i]=ans;
}
for (int i=n+1;i<=2*n;i++)
{
if (a[i]>-q.top())
{
ans+=a[i]+q.top();
q.pop();
q.push(-a[i]);
}
f[i]=ans;
}
while (!q.empty()) q.pop();
ans=0;
for (int i=3*n;i>2*n;i--)
{
q.push(a[i]);
ans+=a[i];
}
ret=f[2*n]-ans;
for (int i=2*n;i>n;i--)
{
if (a[i]<q.top())
{
ans-=q.top();
ans+=a[i];
q.pop();
q.push(a[i]);
}
ret=max(ret,f[i-1]-ans);
}
cout<<ret;
}
E - RGB Sequence
题面
There are N squares arranged in a row. The squares are numbered 1, 2, …, N, from left to right.
Snuke is painting each square in red, green or blue. According to his aesthetic sense, the following M conditions must all be satisfied. The i-th condition is:
- There are exactly xi different colors among squares li, li+1, …, ri.
In how many ways can the squares be painted to satisfy all the conditions? Find the count modulo 109+7.
题意
给出m条约束条件。问一个只有RGB的序列的方案有多少种
令dp[r][g][b]
- r为red最后出现的位置
- g为green最后出现的位置
- b为blue最后出现的位置
dp[r][g][b]转移到max{r,g,b}+1的位置,枚举放rgb,然后判断是否可行。
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll m;
ll dp[305][305][305];
const ll MOD = 1e9+7;
vector<pair<int, int>> v[305];
bool check(int r, int g, int b)
{
int k = max({r, b, g});
for(auto pp: v[k])
{
int ct = 0;
int l = pp.first;
if (r >= l) ct++;
if (g >= l) ct++;
if (b >= l) ct++;
if (ct != pp.second) return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for (int i=0;i<m;++i)
{
int l,r,x;
cin>>l>>r>>x;
v[r].push_back({l,x});
}
dp[0][0][0]=1;
ll ret=0;
for (int r=0;r<=n;++r)
{
for (int g=0;g<=n;++g)
{
for (int b=0;b<=n;++b)
{
ll c=dp[r][g][b];
if (!c) continue;
if (!check(r,g,b))
{
dp[r][g][b]=0;
continue;
}
int k=max({r,g,b}) + 1;
if (k-1 == n)
{
ret+=dp[r][g][b];
ret%=MOD;
}
dp[k][g][b]+=dp[r][g][b] % MOD;
dp[r][k][b]+=dp[r][g][b] % MOD;
dp[r][g][k]+=dp[r][g][b] % MOD;
}
}
}
cout<<ret;
}
F - Lotus Leaves
题面
There is a pond with a rectangular shape. The pond is divided into a grid with H rows and W columns of squares. We will denote the square at the i-th row from the top and j-th column from the left by (i, j).
Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, S, there is a frog trying to get to another leaf T. The state of square (i, j) is given to you by a character aij, as follows:
- . : A square without a leaf.
- o : A square with a leaf floating on the water.
- S : A square with the leaf S.
- T : A square with the leaf T.
The frog will repeatedly perform the following action to get to the leaf T: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located."
Snuke is trying to remove some of the leaves, other than S and T, so that the frog cannot get to the leaf T. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.
题意
看不懂
代码
//null
比赛总结
反应好迟钝啊,B做出来已经快结束了,好在还是做出来了
有种做div1的错觉,哈哈哈哈(逃
比赛链接
http://arc074.contest.atcoder.jp/
Atcoder Regular-074 Writeup的更多相关文章
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder Regular Contest 092
AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...
- AtCoder Regular Contest 093
AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
- AtCoder Regular Contest 095
AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
- AtCoder Regular Contest 096
AtCoder Regular Contest 096 C - Many Medians 题意: 有A,B两种匹萨和三种购买方案,买一个A,买一个B,买半个A和半个B,花费分别为a,b,c. 求买X个 ...
- AtCoder Regular Contest 097
AtCoder Regular Contest 097 C - K-th Substring 题意: 求一个长度小于等于5000的字符串的第K小子串,相同子串算一个. K<=5. 分析: 一眼看 ...
- AtCoder Regular Contest 098
AtCoder Regular Contest 098 C - Attention 题意 给定一个只包含"E","W"字符串,可以花一的花费使他们互相转换.选定 ...
随机推荐
- Linux系统挂载只读改成读写
1.mount命令可用于查看哪个模块输入只读,一般显示为: [root@localhost ~]# mount /dev/cciss/c0d0p2 on / type ext3 (rw) proc o ...
- linux下安装以及升级npm,node的方法
1.最开始使用阿里云文档提供的安装方法一直都是失败的状态,后来找到了新的方法重新安装,按照以下操作一步一步的走即可实现,亲测可用 2.安装完之后,会发现npm和node的版本都偏低,需要重新升级以下, ...
- springboot 日志1
技术交流群: 816227112 Spring Boot在所有内部日志中使用Commons Logging,但是默认配置也提供了对常用日志的支持,如:Java Util Logging,Log4J, ...
- css布局之头尾固定中间高度自适应
被这个问题困扰了很久.大神别鄙视我,我是搞后台开发的....试过了很多方法,比如设定高度100%.同事用的js计算高度,我对js设置的方式一直觉得不够好,尽管设置高度为100%的方式更差,直到发现了一 ...
- ios证书安装和打包流程
iOS开发流程 1.拿到源文件 2文件目录大致名字 一.证书配置 参考网站:http://www.jianshu.com/p/9d9e3699515e (证书配置参考地址) 准备工作 首先要有苹 ...
- 基础数据类型补充,及capy daty7
1,基础数据类型,总结补充. int:bit_lenth() str: captilze() 首字母大写,其余小写. upper() 全大写. lower() 全小写. find() 通过元素找索引, ...
- Jmeter常用脚本开发之Junit Request
说明:Junit Request就是把Junit测试框架的自动化用例在jmeter上执行 步骤: 1.创建Java工程,编写Junit自动化测试用例 2.然后把用例打成jar包,复制到Jmter的li ...
- JoyOI1940 创世纪
一道基环树+树形\(DP\) 原题链接 显然输入的是内向基环树森林,且我们可以单独考虑每一棵基环树. 既然是基环树,自然先\(dfs\)找环,然后随便找环上的一点\(r\),将其与\(A[r]\)的边 ...
- Vim中如何使用正则进行搜索
#set magic这句的作用在于将vim的正则打开. 这样就可以搜索了. 至于正则的相关的内容.在此抄一份.以免于下次自己还要去百度. 符号 匹配 . (dot) 任意单一字符 \d 任意一位数字 ...
- MySQL学习笔记-MySQL数据库优化实践[转]
最近一段时间,我们整理了一些关于Percona,Linux,Flashcache,硬件设备的优化经验,分享给大家: 硬件 1.开启BBWC RAID卡都有写cache(Battery Backed W ...