AtCoder Beginner Contest 136
AtCoder Beginner Contest 136
A - +-x
直接取\(max\)即可。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int a, b;
cin >> a >> b;
cout << max(a + b, max(a - b, a * b));
return 0;
}
B - One Clue
直接输出,注意判断左右边界。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int k, x;
cin >> k >> x;
for(int i = max(-1000000, x - k + 1); i <= min(1000000, x + k - 1); i++) cout << i << ' ';
return 0;
}
C - Green Bin
\(map\)统计\(string\)出现次数即可。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
map <string, int> mp;
string s;
int n;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
ll ans = 0;
for(int i = 1; i <= n; i++) {
cin >> s;
sort(s.begin(), s.end());
if(mp.find(s) != mp.end()) ans += mp[s];
mp[s]++;
}
cout << ans;
return 0;
}
D - Summer Vacation
时间倒流。
每一个工作只能在某一个时刻之前开始进行才能获得收益。考虑倒序枚举时间,在每一个位置将所有工作加入,取最大收益即可。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, m;
vector <int> c[N];
struct node{
int A, B;
}a[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i].B >> a[i].A;
for(int i = 1; i <= n; i++) {
if(a[i].B <= m) c[m - a[i].B].push_back(a[i].A);
}
priority_queue <int> q;
int ans = 0;
for(int i = m - 1; i >= 0; i--) {
for(auto it : c[i]) q.push(it);
if(!q.empty()) {
ans += q.top(); q.pop();
}
}
cout << ans;
return 0;
}
E - Coins Respawn
首先\(dfs\)一次找到所有能够到达\(n\)的点,然后在这些点上面跑\(spfa\)+判正环就行。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2505, M = 5005;
int n, m, p;
struct Edge{
int u,v,w,next;
}e[M<<1];
int tot, head[N];
void adde(int u,int v,int w){
e[tot].u=u;e[tot].v=v;e[tot].w=w;e[tot].next=head[u];head[u]=tot++;
}
bool ok[N], vis[N];
bool g[N][N];
int c[N], d[N], dis[N];
void dfs(int u) {
ok[u] = 1;
for(int i = 1; i <= n; i++) {
if(g[u][i] && !ok[i]) dfs(i);
}
}
int spfa(int s){
queue <int> q;
memset(d,0xcf,sizeof(d));
memset(vis,0,sizeof(vis));memset(c,0,sizeof(c));
q.push(s);vis[s]=1;d[s]=0;c[s]=1;dis[s]=0;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=0;
if(c[u]>n){
return d[0];
}
for(int i=head[u];i!=-1;i=e[i].next){
int v=e[i].v;
if(!ok[v]) continue;
if(d[v]<d[u]+e[i].w){
d[v]=d[u]+e[i].w;
dis[v]=dis[u]+1;
if(!vis[v]){
vis[v]=1;
q.push(v);
c[v]++;
}
}
}
}
return d[n];
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> p;
memset(head, -1, sizeof(head));
for(int i = 1; i <= m; i++) {
int u, v, w; cin >> u >> v >> w;
adde(u, v, w - p);
g[v][u] = 1;
}
dfs(n);
int t = spfa(1);
if(t == d[0]) cout << -1;
else cout << max(0, t);
return 0;
}
F - Polynomial Construction
考虑拉格朗日插值,那么答案就是:
\]
现在就考虑如何快速求\(\prod_{j\neq i}x-j\)。
这部分可以直接递推计算,设\(dp[i][j]\)表示考虑\(\prod_{k=0}^{i}x-k\)的结果中\(x^j\)的系数是多少,那么就有:
- \(dp[i][0]=dp[i-1][0]*(-i)\)
- \(dp[i][j]=dp[i-1][j-1]-dp[i-1][j]*i\)
因为式子中有限制条件:\(j\neq i\),那么就考虑如何去掉一个\(x-i\):
- \(dp[n-1][j]=dp[n-1][j+1](if:i=0)\)
- \(dp[n-1][j]=\frac{dp[n-1][j]-tmp}{i}(else)\),\(tmp\)表示前面的对后面的贡献。
详见代码:
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000;
int n, mod;
int a[N], res[N];
ll qp(ll a, ll b) {
ll ans = 1;
while(b) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int inv[N], inv2[N];
int dp[N][N];
int add(int x, int y) {
x += y;
if(x >= mod) x -= mod;
return x;
}
int sub(int x, int y) {
x -= y;
if(x < 0) x += mod;
return x;
}
int mul(ll x, ll y) {
x = x * y % mod;
if(x < 0) x += mod;
return x;
}
void pre() {
for(int i = 1; i <= n; i++) inv[i] = qp(i, mod - 2);
for(int i = 1; i <= n; i++) inv2[i] = qp(mod - i, mod - 2);
dp[0][1] = 1;
for(int i = 1; i < n; i++) {
for(int j = 0; j <= i + 1; j++) {
dp[i][j] = mul(dp[i - 1][j], mod - i);
if(j) dp[i][j] = add(dp[i][j], dp[i - 1][j - 1]);
// cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n; mod = n;
for(int i = 0; i < n; i++) cin >> a[i];
pre();
for(int i = 0; i < n; i++) if(a[i]) {
int ans = 1;
for(int j = 0; j < n; j++) {
if(i > j) ans = mul(ans, inv[i - j]);
if(i < j) ans = mul(ans, inv2[j - i]);
}
int tmp = 0;
if(i == 0) tmp = dp[n - 1][1];
res[0] = add(res[0], mul(ans, tmp));
for(int j = 1; j < n; j++) {
tmp = mul(sub(dp[n - 1][j], tmp), inv2[i]);
if(i == 0) tmp = dp[n - 1][j + 1];
res[j] = add(res[j], mul(ans, tmp));
}
}
for(int i = 0; i < n; i++) cout << res[i] << " \n"[i == n - 1];
return 0;
}
AtCoder Beginner Contest 136的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
- AtCoder Beginner Contest 075 C bridge【图论求桥】
AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...
随机推荐
- Linux 下配置 iSCSI 客户端
安装客户端软件 Redhat/Centos: yum install -y iscsi-initiator-utils Debian/Ubuntu: apt-get install open-iscs ...
- Spring JDBC最佳实践(1)
原文地址:https://my.oschina.net/u/218421/blog/38513 Spring提供了两种使用JDBC API的最佳实践,一种是以JdbcTemplate为核心的基于Tem ...
- SQL join 三种扩展用法
以前学习,只知道 LEFT JOIN.RIGHT JOIN.INNER JOIN.FULL JOIN,共四种集合,然而加上一些条件,可以组合成另外三种集合,直接上图.
- something want to write
1.时间戳不能相信是因为机器时间有误差.相当于机器不断电的跑着时钟. 2.写log的时候记得log别人的ip,不然没办法很好的debug.
- 类的练习3——python编程从入门到实践
9-13 使用OrderedDict: 在练习6-4中,使用一个标准字典来表示词汇表.使用OrderedDict类来重写这个程序,并确认输出的顺序与在字典中添加的键值对的顺序一致. from coll ...
- python安装pyautogui
一.问题在安装使用[pip install pyautogui]的时候会出现如下的错误: ERROR: Complete output from command python setup.py egg ...
- 【题解】PERIOD - Period [POJ1961] [SP263]
[题解]PERIOD - Period [POJ1961] [SP263] 在进入这道题之前,我们需要了解 kmp 算法 不知道的童鞋可以去看一下Silent_EAG(一个可爱的女孩纸)的讲解. 关于 ...
- 二十三、并发编程之深入解析Condition源码
二十三.并发编程之深入解析Condition源码 一.Condition简介 1.Object的wait和notify/notifyAll方法与Condition区别 任何一个java对象都继承于 ...
- SQL Server优化之SET STATISTICS开关(转载)
一.准备工作 缓存对于某个查询的性能影响十分之大,所以优化之前要清空缓存. 清除Buffer Pool里面的所有缓存 DBCC DROPCLEANBUFFERS 清除Buffer Pool里的所有缓存 ...
- U9-ERP BuildupDesigner 操作
它的数据库文件配制 D:\UFIDA\UBFV50\U9.VOB.Product.UBF\UBFStudio\Runtime\environment.xml