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. 关于jQuery中nth-child和nth-of-type的详解

    首先贴出来HTML的代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. WebStorm7.0的破解版

    EMBRACE 24718-1204201000001h6wzKLpfo3gmjJ8xoTPw5mQvYYA8vwka9tH!vibaUKS4FIDIkUfy!!f3C"rQCIRbShpS ...

  3. detectron安装+caffe2安装

    detectron安装+caffe2安装 因为想跑一下facebook最近开源的detectron物体检测平台,所以安装caffe2+detectron 总结: 一定要好好看官方安装教程:https: ...

  4. 剑指offer(第2版)刷题 Python版汇总

    剑指offer面试题内容 第2章 面试需要的基础知识 面试题1:赋值运算符函数 面试题2:实现Singleton模式  解答 面试题3:数组中重复的数字 解答 面试题4:二维数组中的查找 解答 面试题 ...

  5. web应用与web框架(Day65)

    Web应用 对于所有的web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端 import socket def handle_request(client): ...

  6. 微信小程序组件checkbox

    表单组件checkbox:官方文档 Demo Code: JS Page({ data:{ items:[ {name: 'USA', value: '美国'}, {name: 'CHN', valu ...

  7. ruby underscore

    “examScore".underscore : exam_score "ExamScore".underscore: exam_score

  8. javascript DOM dindow.docunment对象

    一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunment.getElementById(&qu ...

  9. 对 java 设计模式的一些了解 (正在学习整理中)

    A .设计模式的作用 从书上摘话给你们看看 帮助我们将应用组织成容易了解,容易维护,具有弹性的架构,建立可维护的OO系统,要诀在于随时想到系统以后可能需要的变化以及应付变化的原则. 这么复杂的解释肯定 ...

  10. Flume1.7.0的安装与使用

    Flume下载后,解压,新增一个配置文件,写入配置即可 我将配置文件写在 conf 下,取名为 flume-conf-spooldir.properties Flume 运行命令: bin/flume ...