Codeforces Round #566 div 2
A.Filling Shapes
题意:
用多个2x1的木块通过不同的组合方式构成一个3xn的矩形,问有多少种组合方式
思路:
由于木块是2x1的所以当n为奇数时是无法构成成功的所以我们可以去除这个情况;
当n为偶数时我们把矩形分解为多个3x2的小矩形,每个矩形由两个木块构成,每个小矩形有两种构成方式,所以大矩形就有2^(n/2)种方式;
#include<math.h>
#include<stdio.h>
int main() {
int i,j;
int n;
cin>>n;
if(n%2==0)
printf("%d\n",power(2,n/2));
else
printf("0\n");
return 0;
}
B.Plus from Picture
题意:
问图片中是否有一个由"“构成的十字架,并且有且仅有一个十字架
思路:
很简单我们遍历一遍,每次遍历扫描到” * “我们就扫描他的上下左右四面将”“全部记录判断是否与所有的”*"号数量相等
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[505][505];
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
int tot=0;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]=='*') tot++;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(s[i][j]=='*'){
int a=0,b=0,c=0,d=0;
for(int k=i-1;k>=1&&s[k][j]=='*';k--) a++;
for(int k=i+1;k<=n&&s[k][j]=='*';k++) c++;
for(int k=j+1;j<=m&&s[i][k]=='*';k++) b++;
for(int k=j-1;j>=1&&s[i][k]=='*';k--) d++;
if(a+c+d+b==tot-1&&a>=1&&b>=1&&c>=1&&d>=1){
printf("YES");
return 0;
}
}
}
}
printf("NO");
}
C.Beautiful Lyrics
题意:
题目给你n组字符串,你需要找到满足
第一行的第一个单词中的元音数量与第二行的第一个单词中的元音数量相同。
第一行的第二个单词中的元音数量与第二行的第二个单词中的元音数量相同。
第一行的最后一个元音与第二行的最后一个元音相同。请注意,元音后可能有辅音。
这三个条件的字符串对
思路
将每个字符串的元音个数与最后一个元音记录,将元音个数相等最后一个元音相同的放在一个对里面,将元音个数相等最后一个元音不相同的放在一个对里面,然后输出即可
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
const int N=1e5+50,M=1e6+50;
int n,d[127],l[M][6];
string c[N];
vector<pair<int,int> >fi,se;
void print(int x,int y,int z,int a){
cout<<c[x]<<" "<<c[y]<<endl<<c[z]<<" "<<c[a]<<endl;
}
int main(){
d['a']=1;d['e']=2;d['i']=3;d['o']=4;d['u']=5;
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>c[i];
int len=c[i].length(),tot=0,la;
for(int j=0;j<len;j++)if(d[c[i][j]])tot++,la=d[c[i][j]];
if(l[tot][la]){
se.pb(mp(l[tot][la],i));
l[tot][la]=0;
}
else l[tot][la]=i;
}
for(int i=1;i<=1e6;i++){
int la=0;
for(int j=1;j<=5;j++){
if(l[i][j]){
if(la)fi.pb(mp(la,l[i][j])),la=0;
else la=l[i][j];
}
}
}
while(fi.size()<se.size()){
fi.pb(se.back());
se.pop_back();
}
printf("%d\n",se.size());
for(int i=0;i<se.size();i++)print(fi[i].first,se[i].first,fi[i].second,se[i].second);
return 0;
}
E. Product Oriented Recurrence
题意:
给你c,f1,f2,f3让你按照题目给出的公式计算出fn;
思路:
很明显我们通过递推将fn用c,f1,f2,f3的次方表示;
于是我们就只需要找到c,f1,f2,f3的次方x1,x2,x3,x4即可
我们通过矩阵快速幂求出x1,x2,x3,x4即可
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const int Mod(1e9 + 7);
struct Matrix_t
{
int a[5][5];
Matrix_t()
{
memset(a, 0, sizeof(a));
}
Matrix_t operator * (const Matrix_t & T)
{
Matrix_t ans;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
for(int k = 0; k < 5; k++)
ans.a[i][j] = (ans.a[i][j] + (ull) a[i][k] * T.a[k][j]) % (Mod - 1);
return ans;
}
} A;
Matrix_t fexp(Matrix_t x, ll k)
{
Matrix_t res = x;
for(--k; k; k >>= 1, x = x * x)
if(k & 1) res = res * x;
return res;
}
int fexp(int x, ll k)
{
int res = 1;
for(; k; k >>= 1, x = (ull) x * x % Mod)
if(k & 1) res = (ull) res * x % Mod;
return res;
}
int main()
{
ll n;
int f1, f2, f3, c;
scanf("%lld%d%d%d%d", &n, &f1, &f2, &f3, &c);
A.a[0][0] = A.a[0][1] = A.a[0][2] = A.a[0][3] = 1;
A.a[1][0] = A.a[2][1] = A.a[3][3] = 1;
A.a[3][4] = 2, A.a[4][4] = 1;
A = fexp(A, n - 3);
int ans = (ull) fexp(f3, A.a[0][0]) * fexp(f2, A.a[0][1]) % Mod * fexp(f1, A.a[0][2]) % Mod * fexp(c, A.a[0][4]) % Mod * fexp(c, A.a[0][3] * 2) % Mod;
printf("%d\n", ans);