http://codeforces.com/contest/678

A:水题

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int main()
{
int n,k;
scanf("%d%d",&n,&k);
if(n%k==)printf("%d\n",n+k);
else printf("%d\n",((int)(n/k)+)*k);
return ;
}
/******************** ********************/

A

B:题意有点难懂,意思就是给你一个年份n,要求你找到下一个每天都和n相同的年份(指该年的第一天星期和n年相同,天数也相同)

解法:直接暴力,求天数的综合,判断能不能整除7,还有是不是闰年即可

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; bool leap(int x)
{
return x%==||(x%==&&x%!=);
}
int main()
{
// cout<<(3*365+366)%7<<endl;
int y;
scanf("%d",&y);
ll te=;
for(int i=y;;i++)
{
if(leap(i))te+=;
else te+=;
if(te%==)
{
if(leap(y)==leap(i+))
{
printf("%d\n",i+);
return ;
}
}
}
return ;
}
/******************** ********************/

B

C:题意:给n个块,整除a可以填红色,整除b可以填蓝色,红色和蓝色的块分别有一个价值,求填完的最大值

解法:先1到n,整除a的填上,整除b的填上,然后会出现重复,我们把能整除a,b的删掉价值小的那个颜色

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int main()
{
ll n,a,b,p,q;
scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
ll aa=n/a;
ll bb=n/b;
if(p>q)bb-=n/(a/__gcd(a,b)*b);
else aa-=n/(a/__gcd(a,b)*b);
printf("%lld\n",p*aa+q*bb);
return ;
}
/******************** ********************/

C

D:给你一个递推式g(x)^n=a*g(x)^(n-1)+b,g(x)^0=x,给你abxn,求g(x)^n的值

很明显的矩阵快速幂,递推关系式是

(g(x)^n)=( a     b)(g(x)^(n-1))

(    1    )=(0      1)(       1      )

也可以用推公式然后逆元搞,公式是g(x)^n=a^n*x+b*(1-a^n)/(1-a)

 #include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; struct Node{
ll row,col;
ll a[N][N];
};
Node mul(Node x,Node y)
{
Node ans;
memset(ans.a,,sizeof ans.a);
ans.row=x.row,ans.col=y.col;
for(ll i=;i<x.row;i++)
for(ll j=;j<y.row;j++)
for(ll k=;k<y.col;k++)
ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k]+mod)%mod;
return ans;
}
Node quick_mul(Node x,ll n)
{
Node ans;
ans.row=x.row;
ans.col=x.col;
memset(ans.a,,sizeof ans.a);
for(int i=;i<ans.row;i++)ans.a[i][i]=;
while(n){
if(n&)ans=mul(ans,x);
x=mul(x,x);
n/=;
}
return ans;
}
ll quick(ll a,ll b)
{
ll ans=;
while(b)
{
if(b&)ans=ans*a%mod;
a=a*a%mod;
b>>=;
}
return ans;
}
int main()
{
ll aa,bb,n,x;
scanf("%lld%lld%lld%lld",&aa,&bb,&n,&x);
Node A,B;
A.row=,A.col=;
A.a[][]=aa,A.a[][]=bb;
A.a[][]=,A.a[][]=;
B.row=,B.col=;
B.a[][]=x;
B.a[][]=;
ll ans=(mul(quick_mul(A,n),B).a[][]+mod)%mod;
printf("%lld\n",ans);
return ;
}
/******************** ********************/

D

E:有n个人相互决斗,给出i赢j的概率,要求找一种安排方案,让1号选手获胜的最大概率

状压(概率)dp,由于从赢到输不太好处理,于是我们考虑从输到赢逆推,

用dp[i][j]表示i状态下,j是当前擂主的1号最后获胜的最大概率

当i状态下j,k都是存活的,那么dp[i][j]可以转移到dp[i^(1<<k)][j],此时j是擂主,j和k打,k输,也可以转移到dp[i^(1<<j)][k],此时j是擂主,j和k打,j输,再乘上获胜的概率即可

有转移方程dp[i][j]=max(dp[i][j],dp[i^(1<<j)][k]*win[k][j]+dp[i^(1<<j)][k]*win[j][k]);

当只有1号时,存活概率为1,因此,边界值dp[1][0]=1;最后从所有人都存活的状态中找概率最大的即可

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; double dp[N][];
double win[][];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
for(int j=;j<n;j++)
scanf("%lf",&win[i][j]);
dp[][]=;
for(int i=;i<(<<n);i++)
{
for(int j=;j<n;j++)
{
if((i>>j)&)
{
for(int k=;k<n;k++)
{
if(j==k)continue;
if((i>>k)&)
{
dp[i][j]=max(dp[i][j],dp[i^(<<j)][k]*win[k][j]+dp[i^(<<k)][j]*win[j][k]);
}
}
}
}
}
double ans=0.0;
for(int i=;i<n;i++)
ans=max(ans,dp[(<<n)-][i]);
printf("%.12f\n",ans);
return ;
}
/******************** ********************/

E

F:题意:n个操作,第一种是加一个二元组{x,y}到集合中,第二种删除i号操作加入的二元组,第三种给你一个p,求集合中最大的x*p+y

解法:对于第三种操作假设b=x*p+y,y=-p*x+b,那么就是求经过x,斜率为-p直线的截距,那么我们可以维护一个凸包来求解,当然直接遍历凸包上的点肯定是不行的,所以我们画出凸包的图,假设p为负数,那么我们从第三象限扫一遍到第一象限,可以看出对于凸包上的点,这个截距是单峰的,也因为凸包上的点是有序的,可以得出无论p是多少,结果对于凸包上的有序点来说肯定是单峰的,那么我们可以用三分来求解。

还有一个问题是这个凸包是动态的,我们不能每次都扫一遍凸包,这样太费时了,可以看出对于每一个加入的二元组,它都有一个作用时间区间,我们可以对这个时间区间建立一颗线段树,每个节点维护在该时间区间出现的二元组,(这样我们就同时解决了操作1和操作2),建好线段树之后,我们对每一个节点求一次凸包,当查询时,我们在线段树上走一遍对每个点三分一下,找出最大的值即可

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define inf 9223372036854775807ll
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+; struct point{
ll x,y;
point(ll x=,ll y=):x(x),y(y){}
bool operator <(const point &rhs)const{
return x<rhs.x||(x==rhs.x&&y<rhs.y);
}
point operator +(const point &rhs)const{
return point(x+rhs.x,y+rhs.y);
}
point operator -(const point &rhs)const{
return point(x-rhs.x,y-rhs.y);
}
ll operator *(const point &rhs)const{
return x*rhs.y-y*rhs.x;
}
}p[N];
int en[N];
ll ask[N],ans;
vector<point>pointset[N<<];
void update(int L,int R,int l,int r,int rt)
{
// printf("%d------%d\n",l,r);
if(L<=l&&r<=R)
{
// puts("+++++++++++");
pointset[rt].pb(p[L]);
return ;
}
int m=(l+r)>>;
if(L<=m)update(L,R,ls);
if(m<R)update(L,R,rs);
}
void dfs(int l,int r,int rt)
{
vector<point>& v=pointset[rt];
if(!v.empty())sort(v.begin(),v.end());
if(v.size()>)
{
int i,j;
for(i=,j=;i<v.size();i++)
{
while(j>&&(v[j]-v[j-])*(v[i]-v[j])>=)j--;
j++;
v[j]=v[i];
}
while(v.size()>j+)v.pop_back();
}
if(l==r)return ;
int m=(l+r)>>;
dfs(ls);dfs(rs);
}
ll fun(point p,ll v){return p.x*v+p.y;}
ll solve(vector<point> &v,ll c)
{
ll ans=-inf;
int l=,r=v.size()-;
while(r-l>)
{
int m1=(l*+r)/;
int m2=(l+r*)/;
if(fun(v[m1],c)<fun(v[m2],c))l=m1;
else r=m2;
}
for(int i=l;i<=r;i++)ans=max(ans,fun(v[i],c));
return ans;
}
void query(int pos,ll c,int l,int r,int rt)
{
ans=max(ans,solve(pointset[rt],c));
if(l==r)return;
int m=(l+r)>>;
if(pos<=m)query(pos,c,ls);
else query(pos,c,rs);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
en[i]=-;
ask[i]=-inf;
int t;
scanf("%d",&t);
if(t==)
{
scanf("%lld%lld",&p[i].x,&p[i].y);
en[i]=n;
}
else if(t==)
{
int x;
scanf("%d",&x);
en[x]=i-;
}
else
{
scanf("%lld",&ask[i]);
}
}
for(int i=;i<=n;i++)
if(en[i]!=-)
update(i,en[i],,n,);
dfs(,n,);
// for(int i=0;i<pointset[1].size();i++)
// {
// point te=pointset[1][i];
// printf("%lld %lld\n",te.x,te.y);
// }
for(int i=;i<=n;i++)
{
if(ask[i]!=-inf)
{
ans=-inf;
query(i,ask[i],,n,);
if(ans==-inf)puts("EMPTY SET");
else printf("%lld\n",ans);
}
}
return ;
}
/******************** ********************/

F

Educational Codeforces Round 13的更多相关文章

  1. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  2. Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...

  3. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  4. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  5. Educational Codeforces Round 13 C. Joty and Chocolate 水题

    C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...

  6. Educational Codeforces Round 13 B. The Same Calendar 水题

    B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...

  7. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

  8. Educational Codeforces Round 13 A、B、C、D

    A. Johny Likes Numbers time limit per test 0.5 seconds memory limit per test 256 megabytes input sta ...

  9. Educational Codeforces Round 13 A

    Description Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x gr ...

随机推荐

  1. Super Jumping! Jumping! Jumping!---hdu1087(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题意就是给你n个数,找出某个序列的最大和,这个序列满足依次增大的规则: 哎,这个题之前做过,但是 ...

  2. Delphi中MD5实现方法(转)

    原来写过一个计算MD5的程序,是用了一个叫MD5.pas的单元,使用起来还算简单,但还有更简单的办法,安装了indy就会有IdHashMessageDigest单元(delphi 7默认安装indy) ...

  3. 【转】如约而至:微信自用的移动端IM网络层跨平台组件库Mars已正式开源

    网上看到关于微信官方的跨平台跨业务的终端基础组件Mars的介绍文章,转载这这里.源代码: https://github.com/Tencent/mars作者:男人链接:https://zhuanlan ...

  4. 搜狐云景client工具评測之WordPress的搭建

    搜狐云景是搜狐推出的一款PaaS产品,眼下还处在公測阶段,拿到邀请码后试用了一下,感觉还不错. 搜狐云景提供了四种方式部署应用,感觉应该能够满足各种口味的码农:1. zip包的形式在网页上传并部署   ...

  5. Leetcode 之 Set Mismatch

    645. Set Mismatch 1.Problem The set S originally contains numbers from 1 to n. But unfortunately, du ...

  6. DL for objection detection

    在计算机视觉领域,"目标检测"主要解决两个问题:图像上多个目标物在哪里(位置),是什么(类别).围绕这个问题,人们一般把其发展历程分为3个阶段:1. 传统的目标检测方法2. 以R- ...

  7. ThreadLocal 示例

    ThreadLocal, 从字面意思上看是本地线程. 但实际上它是一个线程本地变量.它的功能就是为每一个使用该变量的线程都提供一个变量值的副本, 从而使得不会与其他线程的副本冲突. 与使用synchr ...

  8. python16_day18【Django_Form表单、分页】

    一.表单 Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 1.Form类 创建Form类时,主 ...

  9. github使用ssh秘钥的好处以及设置(转)

    git使用https协议,每次pull,push都要输入密码,使用git协议,使用ssh秘钥,可以省去每次输密码 大概需要三个步骤:一.本地生成密钥对:二.设置github上的公钥:三.修改git的r ...

  10. 2018 ACM 国际大学生程序设计竞赛上海大都会 F - Color it (扫描线)

    题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白 ...