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. 第20章—跨域访问(CORS)

    spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...

  2. linux下Pl353 NAND Flash驱动分析

    linux的NAND Flash驱动位于drivers/mtd/nand子文件夹下: nand_base.c-->定义通用的nand flash基本操作函数,如读写page,可自己重写这些函数 ...

  3. 在MySQL数据库的表中可以给某个整数类型的字段赋字符串类型的值

  4. git rm与直接rm的区别

    git rm 行为: 1.删除一个文件 2.将被删除的这个文件纳入缓存区 $ git rm a rm 'a' $ git status On branch master Changes to be c ...

  5. 分布式计算hadoop三大组件

    设计原则:移动计算,而不是移动数据 计算层:Map/Reduce调度层:YARN数据层:HDFS 这三层之间没有必然的依赖性,只是经常这么搭配,而且都是hadoop那个包里一起安装的,三层都可以独立运 ...

  6. oracle中记录被另一个用户锁住的原因与解决办法

    oracle数据中删除数据时提示“记录被另一个用户锁住” 解决方法: 1.查看数据库锁,诊断锁的来源及类型: select object_id,session_id,locked_mode from ...

  7. html-3,table 表格标签 tr th td caption thead tbody tfoot 的简单使用

    <!-- table border='1' style="border-collapse:collapse;" border 表格的像素宽度 border-collapse: ...

  8. Spring @Qualifier l转

    当候选 Bean 数目不为 1 时的应对方法 在默认情况下使用 @Autowired 注释进行自动注入时,Spring 容器中匹配的候选 Bean 数目必须有且仅有一个.当找不到一个匹配的 Bean ...

  9. 调试ASP.NET网站IIS环境问题解决方法汇总

    调试网站时出现错误,错误如下: 1. 分析器错误消息: 创建 RewriterConfig 的配置节处理程序时出错: 无法生成临时类(result=1).error CS2001: 未能找到源文件“C ...

  10. [转]《Python爬虫学习系列教程》

    <Python爬虫学习系列教程>学习笔记 http://cuiqingcai.com/1052.html 大家好哈,我呢最近在学习Python爬虫,感觉非常有意思,真的让生活可以方便很多. ...