SRM 11爆0记

难度区间:NOIP提高-

第一题

题意:

滚来滚去

 

Solution

刚开始写了O(n)的60分模拟,打了1h的状态表,结果写砸了只剩35分QAQ

对于30%的数据:O(n^2)模拟

对于60%的数据:O(1)求横向翻转,O(n)模拟向下翻转的情况

对于100%的数据:时间复杂度:O(1)

分类讨论:

用真.骰子模拟可得:

当c%4=0时,ans=r*c/2*7;

当c%4=1时,循环节为(第1-4行):即:1,5,6,2,易得ans=c/4*14*r+循环节sum=(c>>1)*7*r+循环节sum

当c%4=2时,循环节为(第1-6行):      ,同理易得ans

当c%4=3时,循环节为(第1-2行):,同理易得ans

Code:

 1 #include <iostream>
 2 #include <cstdio>
 3 #define ll long long 
 4 using namespace std;
 5 ll r,c,yu2[10],yu1[10];// 1:r 0:l
 6 void read(ll &k)
 7 {
 8     ll f=1;k=0;char c=getchar();
 9     while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
10     while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
11     k*=f;
12 }
13 int main()
14 {
15     freopen("dice.in","r",stdin);
16     freopen("dice.out","w",stdout);
17     read(r);read(c);
18     yu2[1]=5;yu2[2]=11;yu2[3]=19;yu2[4]=28;yu2[5]=36;yu2[0]=0;
19     yu1[1]=1;yu1[2]=6;yu1[3]=12;yu1[0]=0;
20     ll chu=c/4,yu=c%4;
21     if (yu==3)printf("%lld
",chu*14*r+11*r);
22     if (yu==2)printf("%lld
",chu*14*r+42*((ll)r/6)+yu2[r%6]);
23     if (yu==1)printf("%lld
",chu*14*r+14*((ll)r/4)+yu1[r%4]);
24     if (!(c%4))printf("%lld
",r*(c>>1)*7);
25 }
View Code

 

 

原文地址:https://www.cnblogs.com/mczhuang/p/7309159.html