Educational Codeforces Round 13 A、B、C、D
0.5 seconds
256 megabytes
standard input
standard output
Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.
The only line contains two integers n and k (1 ≤ n, k ≤ 109).
Print the smallest integer x > n, so it is divisible by the number k.
5 3
6
25 13
26
26 13
39
题意:找到一个大于n并且被k整除的最小的数;
思路:除+1;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
printf("%I64d\n",(ll)(x/y+)*y);
return ;
}
代码
1 second
256 megabytes
standard input
standard output
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.
Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
2016
2044
2000
2028
50501
50507
Today is Monday, the 13th of June, 2016.
题意:找到这年之后日历相同的年份;
思路:天数整除7并且是同是闰年或平年;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int check(int x)
{
if((x%==&&x%!=)||x%==)
return ;
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
int ans=;
for(i=x;;i++)
{
ans+=check(i)%;
if(ans%==&&(check(x)==check(i+)))
break;
}
cout<<i+<<endl;
return ;
}
代码
1 second
256 megabytes
standard input
standard output
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.
After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).
Print the only integer s — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
5 2 3 12 15
39
20 2 3 3 5
51
题意:1-n中每个整除a的数可以得到p;1-n中每个整除b的数可以得到q;
问最多可以得到多少;
思路:简单的容斥;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
ll gcd(ll x,ll y)
{
return y==?x:gcd(y,x%y);
}
int main()
{
int x,y,z,i,t;
ll n,a,b,p,q;
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
ll aa=n/a;
ll bb=n/b;
ll ans=aa*p+bb*q;
ll lcm=a*b/gcd(a,b);
ans-=n/lcm*min(p,q);
printf("%I64d\n",ans);
return ;
}
代码
1 second
256 megabytes
standard input
standard output
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B,n and x find the value of g(n)(x) modulo 109 + 7.
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long longinteger type and in Java you can use long integer type.
Print the only integer s — the value g(n)(x) modulo 109 + 7.
3 4 1 1
7
3 4 2 1
25
3 4 3 1
79
思路:赤裸裸的矩阵快速幂;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
struct is
{
ll a[][];
};
ll x,m,k,c;
is juzhenmul(is a,is b,ll hang ,ll lie)
{
int i,t,j;
is ans;
memset(ans.a,,sizeof(ans.a));
for(i=;i<=hang;i++)
for(t=;t<=lie;t++)
for(j=;j<=lie;j++)
{
ans.a[i][t]+=(a.a[i][j]*b.a[j][t]);
ans.a[i][t]%=mod;
}
return ans;
}
is quickpow(is ans,is a,ll x)
{
while(x)
{
if(x&) ans=juzhenmul(ans,a,,);
a=juzhenmul(a,a,,);
x>>=;
}
return ans;
}
int main()
{
int y,z,i,t;
ll a,b,n,x;
scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x);
is base;
base.a[][]=a;
base.a[][]=;
base.a[][]=b;
base.a[][]=;
is ans;
memset(ans.a,,sizeof(ans.a));
ans.a[][]=;
ans.a[][]=;
ans=quickpow(ans,base,n);
printf("%I64d\n",(x*ans.a[][]+ans.a[][])%mod);
return ;
}
代码
Educational Codeforces Round 13 A、B、C、D的更多相关文章
- Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water
题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...
- Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维
题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...
- Educational Codeforces Round 45 (Rated for Div. 2) C、D
C. Bracket Sequences Concatenation Problem time limit per test 2 seconds memory limit per test 256 ...
- Educational Codeforces Round 92 (Rated for Div. 2) B、C题解
TAT 第一场codeforces B. Array Walk #暴力 #贪心 题目链接 题意 有\(a1, a2, ..., an\) 个格子(每个格子有各自分数),最初为1号格(初始分数为\(a1 ...
- Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task
题意: 给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能 ...
- Educational Codeforces Round 13 D:Iterated Linear Function(数论)
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
- Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
随机推荐
- Blue Jeans---poj3080(kmp+暴力求子串)
题目链接:http://poj.org/problem?id=3080 题意就是求n个长度为60的串中求最长公共子序列(长度>=3):如果有多个输出字典序最小的: 我们可以暴力求出第一个串的所有 ...
- (转)Unity3d的3种截图方法
下面是我总结的.在u3d中的,三种截屏方法: 1.使用Application类下的CaptureScreenshot方法. void CaptureScreen() { Application.Cap ...
- mysql 正则表达式 regexp rlike not rlike
regexp rlike not rlike 今天在上班的时候突然遇到了一个问题,C+组的同事要删除mysql里面的一些特殊数据,想要正则进行匹配.于是问我,没想到还真的把我难住了,问题如下 ...
- mysql 约束条件 auto_increment 自动增长
约束字段为自动增长,被约束的字段必须同时被key约束 id自动增长,每插入一条记录,自动增长 创建一张表 t20 id 字段设置为 不为空 唯一 自动增长 mysql)); Query OK, row ...
- 机器学习算法(优化)之一:梯度下降算法、随机梯度下降(应用于线性回归、Logistic回归等等)
本文介绍了机器学习中基本的优化算法—梯度下降算法和随机梯度下降算法,以及实际应用到线性回归.Logistic回归.矩阵分解推荐算法等ML中. 梯度下降算法基本公式 常见的符号说明和损失函数 X :所有 ...
- spring Bean装配的几种方式简单介绍
Spring容器负责创建应用程序中的bean同时通过ID来协调这些对象之间的关系.作为开发人员,我们需要告诉Spring要创建哪些bean并且如何将其装配到一起. spring中bean装配有两种方式 ...
- vim中快速定位到某行以及快捷删除多行
vim filename 在命令行中直接输入 numberG 比如 100G直接定位到100行 输入 :set number即显示行号 : i,.d删除从第i行到目前所在行内容
- Linux系统——本地定制化yum仓库部署
1)开启yum仓库配置文件 /etc/yum.conf的keepcache功能 (开启一个新的虚拟机) 将keepcache=0改为1,修改配置文件后重新清空缓存(1默认下载的安装包不删除,才可以实现 ...
- iClap专访:颠覆传统办公方式,规范化产品管理系统
背景:DevStore是成立于2014年的移动互联网企业运营解决方案整合平台,线上资源涉及产品研发,设计,推广运维各个阶段,致力于为互联网从业者提供帮助.iClap是DevStore的全新产品,于20 ...
- 虚拟机Linux系统忘记密码的情况下,修改root或其他用户密码
使用场景 linux管理员忘记root密码,需要进行找回操作. 注意事项:本文基于centos7环境进行操作,由于centos的版本是有差异的,继续之前请确定好版本. 步骤 一.重启系统,在开机过程中 ...