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. Pandas 横向合并DataFrame数据

    需要将两个DataFrame进行横向拼接: 对 A_DataFrame 拼接一列数据: 数据样例如下: 将右侧source_df中的 “$factor” 列拼接到左侧qlib_df中,但左侧数据是分钟 ...

  2. 3509.com 纵横天下虚拟主机,垃圾中的战斗机

    被纵横天下主机(3509.com)这间垃圾公司气疯了,他们公司自己要更换server(空间).居然把我挂在上面的站点数据弄丢了.并且更换连一封Email通知都没有.更离谱的是,跟他们反映这个情况后.他 ...

  3. mysql 建立表之间关系 一对一 练习2

    创建db5数据库 create database db5 charset=utf8; use db5; 例二:一个管理员唯一对应一个用户 用户表: id user password 1 egon xx ...

  4. 006-HotSpot JVM收集器

    一.概述 1.1.图解 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. JVM给出了3类选择:串行收集器.并行收集器.并发收集 ...

  5. ansible安装及使用

    一.ansible介绍 1.ansible简介 官方的title是“Ansible is Simple IT Automation”——简单的自动化IT工具. Ansible跟其他IT自动化技术的区别 ...

  6. [DevOps] 认识一下

    大家都在说DevOps(Develop Operation),大概知道就是开发和运维沟通交流,一条线,然后使产品能够顺利的.短时间内上线.维稳什么的. 今天特意看了下 DockOne里面的一篇文章,再 ...

  7. 使用Stanford Parser进行句法分析

    一.句法分析 1.定义 句法分析判断输入的单词序列(一般为句子)的构成是否合乎给定的语法,并通过构造句法树来确定句子的结构以及各层次句法成分之间的关系,即确定一个句子中的哪些词构成一个短语,哪些词是动 ...

  8. __BEGIN_DECLS __END_DECLS

    http://hi.baidu.com/xiaoxiaolq/blog/item/1edc2af30dd4915a342acc5e.html对__BEGIN_DECLS 和 __END_DECLS 的 ...

  9. python16_day11【MQ、Redis、Memcache】

    一.RabbitMQ 是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消息队列(MQ)是一种应 ...

  10. Python(常用模块)

    模块 模块 本质上就是一个.py文件 内置模块(解释器层面) 第三方模块(Python lib文件) 自定义模块(当前路径) 模块调用,包的概念 在计算机程序的开发过程中,随着程序代码越写越多,在一个 ...