Codeforces Round 313(div1)
题目大意:
给出内角全为120度的六边形的六条边的边长,求由多少边长为1的等边三角形构成。
解题思路:
将六边形补全为一个大的等边三角形,则大的等边三角形的边长为六边形的相邻三边之和,接着减去补的部分。
补的部分是三个边长为认识3个不相邻的六边形边长的长度构成的等边三角形,边长为a的等边三角形,由a*a个边
长为1的小三角形构成。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int main()
{
int a[10];
for(int i=0;i<6;i++)
{
scanf("%d",&a[i]);
}
long long cur=a[0]+a[1]+a[2];
long long ans=cur*cur-a[0]*a[0]-a[2]*a[2]-a[4]*a[4];
cout<<ans<<endl;
return 0;
}
题目大意:
依据给定的规则推断字符串相等。
解题思路:
依照题意递归写就可。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=200000+1000;
char s1[maxn];
char s2[maxn];
int judge(int st1,int en1,int st2,int en2)
{
int sign=0;
for(int i=st1,j=st2;i<=en1;i++,j++)
{
if(s1[i]!=s2[j])
{
sign=1;
break;
}
}
if(sign==0)
return 1;
else
{
if((en1-st1+1)%2==0)
{
int mid1=st1+(en1-st1+1)/2-1;
int mid2=st2+(en2-st2+1)/2-1;
if(judge(st1,mid1,st2,mid2)&&judge(mid1+1,en1,mid2+1,en2))
return 1;
if(judge(st1,mid1,mid2+1,en2)&&judge(mid1+1,en1,st2,mid2))
return 1;
}
}
return 0;
}
int main()
{
int len1,len2;
scanf("%s%s",s1,s2);
len1=strlen(s1);
len2=strlen(s2);
if(len1!=len2)
cout<<"NO\n"<<endl;
else
{
int sign;
sign=judge(0,len1-1,0,len1-1);
if(sign)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
题目大意:
给定h*w的格子,n个不可走的点。从(1,1)到(h,w)点。每次仅仅能向下或者向右。求有多少种走法?
解题思路:
首先先不考虑不可走的点,有C(h+w-2,h-1)种走法,一共走h+w-2步,向下的有h-1步。
接着考虑当中的不可走的
点,对于一个不可走的点(x,y)。它走到这个的点的走法是dp[i],它少走的是dp[i]*C(h-x,w-y,h-x),于是把每一个不可走
的点当为终点。能够求出全部的走法数。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int h,w,n;
const int maxn=200000+100;
const int mod=1000000000+7;
long long c[maxn];
long long inv[maxn];
long long dp[5000];
struct node
{
int x;
int y;
}a[10000];
long long pow_mod(long long a,int b)//矩阵高速幂
{
long long ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%mod;
a=(a*a)%mod;
b=b/2;
}
return ans;
}
long long com(int x,int y)//求组合数C(x,y)
{
return ((c[x]*inv[y])%mod*inv[x-y])%mod;
}
bool cmp(node u,node v)
{
if(u.x==v.x)
return u.y<v.y;
return u.x<v.x;
}
int main()
{
scanf("%d%d%d",&h,&w,&n);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a,a+n,cmp);
long long ans=0;
c[0]=1;
for(int i=1;i<maxn;i++)
c[i]=c[i-1]*i%mod;
inv[0]=1;
for(int i=1;i<maxn;i++)
inv[i]=pow_mod(c[i],mod-2);//费马小定理求逆。a^(p-2)=a^(-1)
ans=com(h+w-2,h-1);
for(int i=0;i<n;i++)
{
dp[i]=com(a[i].x+a[i].y-2,a[i].x-1);
for(int j=0;j<i;j++)//求过第i个点的方法数
{
if(a[j].x<=a[i].x&&a[j].y<=a[i].y)//推断能否够到达i点
{
dp[i]-=(dp[j]*com(a[i].x-a[j].x+a[i].y-a[j].y,a[i].x-a[j].x))%mod;
dp[i]=(dp[i]+mod)%mod;
}
}
ans=(ans-(dp[i]*com(h+w-a[i].x-a[i].y,h-a[i].x))%mod+mod)%mod;
}
cout<<ans<<endl;
return 0;
}
Codeforces Round 313(div1)的更多相关文章
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
- Codeforces Round #313 (Div. 1)
官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少 ...
- dp - Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
Gerald and Giant Chess Problem's Link: http://codeforces.com/contest/559/problem/C Mean: 一个n*m的网格,让你 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon
Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...
- Codeforces Round #313 (Div. 2)B.B. Gerald is into Art
B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/ ...
随机推荐
- 混个脸熟 -- go
一.第一个项目:hello world src/day1/example1/main.go package main import "fmt" func main(){ fmt.P ...
- B - Helpful Maths
Problem description Xenia the beginner mathematician is a third year student at elementary school. S ...
- Prism.Interactivity 之 PopupWindowAction 用法简记
PopupWindow通过InteractionRequestTrigger(EventTrigger的派生类)侦听目标对象(InteractionRequest<T>类型)的Raised ...
- KindEditor文本编辑框的实现
效果图: kindeditor 是一个插件 下载地址: https://files-cdn.cnblogs.com/files/lxnlxn/kindeditor.zip 解压后将其放在项目的js文件 ...
- Shiro图解
- JavaScript异步加载方案
(1) defer,只支持IE defer属性的定义和用法(我摘自w3school网站) defer 属性规定是否对脚本执行进行延迟,直到页面加载为止. 有的 javascript 脚本 docume ...
- Vue初级-样式
整个网页不仅有标签还有css进行渲染,所以,现在讲讲在vue里面加入你想加的css. 在不用vue的时候,有一种内联方式加入css(大概是<div style="..."&g ...
- 【PostgreSQL-9.6.3】log参数的设置
编辑数据目录中的postgresql.conf参数文件,我的数据目录是/usr/local/pgsql/data vi postgresql.conf 找到如下内容: ... #----------- ...
- 【Oracle】重命名数据文件
1)查看当前数据文件位置 SQL> select file_id,file_name,tablespace_name from dba_data_files; FILE_ID FILE_NAME ...
- VHDL之FSM
1 Intro The figure shows the block diagram of a single-phase state machine. The lower section contai ...