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. DRF(4) - 认证、权限组件

    一.引入 通过前面三节课的学习,我们已经详细了解了DRF提供的几个重要的工具,DRF充分利用了面向对象编程的思想,对Django的View类进行了继承,并封装了其as_view方法和dispatch方 ...

  2. 初级dba学习之路参考

    今天周一拖着疲惫的身躯 11点才离开公司,回到家估计写完这篇博客就要17号了. 一个人走在回家的路上,很黑,突然很多感触,一个人在北京拼搏,不敢停止学习的脚步,因为只要停下来就会感觉到孤独. 回顾一下 ...

  3. SQL基础三

    一.SQL ORDER BY 子句 ORDER BY 语句用于对结果集进行排序,默认按照升序对记录进行排序,如果需要按照降序进行排序,需要在后面追加关键字DESC.应用如下: 原始的表:Orders表 ...

  4. Angular 学习笔记 :初识 $digest , $watch , $apply,浅析用法 。

    传统的浏览器事件循环 :浏览器本身一直在等待事件,并作出响应.如果你点击一个button或者在input 中输入字符,我们在 JS 中 监听这些事件并设定了回调函数,那么这些事件被触发以后,回调函数就 ...

  5. Notepad++ c编译环境 64

    准备: mingw64(我是从西西软件园下的) 个人微盘共享地址: http://url.cn/24RAhTf notepad++ 安装 mingw64 系统path路径(bin目录下) Notepa ...

  6. Xamrin开发安卓笔记(二)

    http://www.cnblogs.com/minCS/p/4112617.html Xamrin开发安卓笔记(二)   安装篇 Xamrin开发安卓笔记(一) 昨天调理一天AAPT.EXE 被推出 ...

  7. LeetCode:累加数【306】

    LeetCode:累加数[306] 题目描述 累加数是一个字符串,组成它的数字可以形成累加序列. 一个有效的累加序列必须至少包含 3 个数.除了最开始的两个数以外,字符串中的其他数都等于它之前两个数相 ...

  8. hadoop15---activemq

    java JMS技术 JMS是规范,activeMQ是实现. 用于在两个应用程序之间,或分布式系统中发送消息,进行异步通信. 它类似于JDBC,JDBC 是可以用来访问许多不同关系数据库的 API. ...

  9. Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法

    Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法 一.原因 Python 3 中虽有encoding 参数,但是对于有BOM(如Windows下用记事本指定为utf-8) ...

  10. Apache 浏览器访问限制配置

    浏览器访问限制配置 user_agent收入的浏览器中,我们通过百度,谷歌很容易就可以查到相关的一些资料,方便了我们对知识的查找,但在某些特定情况下,我们并不希望有人可以通过某写搜索引擎直接访问到我们 ...