问题 J: Frosting on the Cake
Posted zangzang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了问题 J: Frosting on the Cake相关的知识,希望对你有一定的参考价值。
问题 J: Frosting on the Cake
时间限制: 1 Sec 内存限制: 128 MB提交: 159 解决: 56
[提交][状态][讨论版][命题人:admin]
题目描述
Iskander the Baker is decorating a huge cake, covering the rectangular surface of the cake with frosting.For this purpose, he mixes frosting sugar with lemon juice and food coloring, in order to produce three kinds of frosting: yellow, pink, and white. These colors are identi?ed by the numbers 0 for yellow,1 for pink, and 2 for white.
To obtain a nice pattern, he partitions the cake surface into vertical stripes of width A1, A2, . . . , An entimeters, and horizontal stripes of height B1, B2, . . . , Bn centimeters, for some positive integer n.
These stripes split the cake surface into n × n rectangles. The intersection of vertical stripe i and horizontal stripe j has color number (i + j) mod 3 for all 1 6 i, j 6 n. To prepare the frosting, Iskander wants to know the total surface in square centimeters to be colored for each of the three colors, and asks for your help.
To obtain a nice pattern, he partitions the cake surface into vertical stripes of width A1, A2, . . . , An entimeters, and horizontal stripes of height B1, B2, . . . , Bn centimeters, for some positive integer n.
These stripes split the cake surface into n × n rectangles. The intersection of vertical stripe i and horizontal stripe j has color number (i + j) mod 3 for all 1 6 i, j 6 n. To prepare the frosting, Iskander wants to know the total surface in square centimeters to be colored for each of the three colors, and asks for your help.
输入
The input consists of the following integers:
? on the first line: the integer n,
? on the second line: the values of A1, . . . , An, n integers separated with single spaces,
? on the third line: the values of B1, . . . , Bn, n integers separated with single spaces.
Limits
The input satis?es 3≤n≤100 000 and 1≤A1, . . . , An, B1, . . . , Bn≤10 000.
? on the first line: the integer n,
? on the second line: the values of A1, . . . , An, n integers separated with single spaces,
? on the third line: the values of B1, . . . , Bn, n integers separated with single spaces.
Limits
The input satis?es 3≤n≤100 000 and 1≤A1, . . . , An, B1, . . . , Bn≤10 000.
输出
The output should consist of three integers separated with single spaces, representing the total area for each color 0, 1, and 2.
样例输入
3
1 1 1
1 1 1
样例输出
3 3 3
////////////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int a[100005]; int b[100005]; int n; long long int aa[5]={0}; long long int bb[5]={0}; memset(aa,0,sizeof(aa)); memset(bb,0,sizeof(bb)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } for(int i=1;i<=n;i++) { scanf("%d",&b[i]); } for(int i=1;i<=n;i++) { if(i%3==1) { aa[1]+=a[i]; bb[1]+=b[i]; } else if(i%3==2) { aa[2]+=a[i]; bb[2]+=b[i]; } else if(i%3==0) { aa[3]+=a[i]; bb[3]+=b[i]; } } // for(int i=1;i<=3;i++) // { // printf("%lld %lld\n",aa[i],bb[i]); // } long long int ans1,ans2,ans3; ans3=aa[1]*bb[1]+aa[3]*bb[2]+aa[2]*bb[3]; ans1=aa[2]*bb[1]+aa[1]*bb[2]+aa[3]*bb[3]; ans2=aa[3]*bb[1]+aa[2]*bb[2]+aa[1]*bb[3]; printf("%lld %lld %lld\n",ans1,ans2,ans3); }
//如果暴力解会超时 所以找规律 把Ai、Bi分为3部分 然后再计算
以上是关于问题 J: Frosting on the Cake的主要内容,如果未能解决你的问题,请参考以下文章
P2905 [USACO08OPEN]农场危机Crisis on the Farm
[Usaco2005 nov]Grazing on the Run 边跑边吃草 BZOJ1742
Codeforces1607 F. Robot on the Board 2(模拟)
Codeforces1607 F. Robot on the Board 2(模拟)
bzoj 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草区间dp
Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path 解决过程