好老的题了,但是还是很有做头的。

总结

  1. 不吸氧看来确实是没法用stl的啊(set常数太大了,开O2也没过)
  2. SPFA没认真学,觉得有堆优化Dijkstra就天下无敌了,今天负边权教我做人
  3. 于是苦逼的只有180分
  4. 第一题我看错了,想了10分钟,本来打算打暴力50分,然后又看对了。 /(ㄒoㄒ)/~~
  5. 后来发现其实打Bellman-Ford可以拿下40分,但是我没有认真想(何况Floyd算法也可以)

小奇挖矿

题目分析

我们发现这道题每个操作只对其后面又影响,然后我们想到DP要求的无后效性,于是我们直接倒着DP一下就好了。

(最重要的是这道题有取东西的顺序)

代码

#include <cstdio>
#include <iostream>
using namespace std; #define forn(i) for(int i=1;i<=n;++i) const int maxn = 1e5 + 10;
int opt[maxn], a[maxn]; int main() {
freopen("explo.in","r",stdin);
freopen("explo.out","w",stdout);
double n, k, c, w;
cin >> n >> k >> c >> w;
forn(i) cin >> opt[i] >> a[i];
double p_1 = 1-0.01*k;
double p_2 = 1+0.01*c;
double ans = 0;
for (int i = n; i; -- i)
if (opt[i] & 1) ans = max(ans, ans * p_1 + a[i]);
else ans = max(ans, ans * p_2 - a[i]);
printf("%.2lf", ans*w);
return 0;
}

小奇的数列

题目分析

emmm,这道题暴力都可以70分。我怕不吸氧set过不了,于是写了个70的部分分,然后写了个stl版正解

70pts: 首先根据抽屉原理,如果询问长度 \(\ge q\) 那就必有前缀和模\(q\)相等,或者这个数本身被\(q\)整除,然后因为\(q \le 200\)直接\(n ^ 2\)暴力

100pts: 考虑已经定下来一端,我们只需要寻找另外一段,是的他们的差值最小就行了,于是自然的写出二分。维护的话,考虑平衡树,或者set都可以。

代码

set

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
typedef long long qword;
#define pb push_back #define forn(i) for(int i=1;i<=n;++i)
#define rep(i,s,t) for(int i=(int)(s);i<=(int)(t);++i) int n, m;
const int maxn = 5e5 + 10;
int a[maxn];
qword sum[maxn]; inline void Init() {
cin >> n >> m;
forn(i) cin >> a[i];
forn(i) sum[i] = sum[i - 1] + a[i];
} qword mod(qword x, int p) {
x %= p;
while (x < 0) x += p;
return x % p;
} inline void work() {
int L, R, Q;
qword ans;
while (m--) {
cin >> L >> R >> Q;
ans = Q;
if (R - L >= Q) {cout << 0 << endl; continue;}
rep(i,L,R) rep(j,i,R)
ans = min(ans, mod(sum[j] - sum[i - 1],Q));
cout << ans << endl;
}
} inline void solve() {
int L, R, Q;
qword ans;
while (m--) {
cin >> L >> R >> Q;
ans = Q;
if (R - L + 1 >= Q) {cout << 0 << endl; continue;}
set<qword> s;
s.insert(0);
rep(i,L,R) {
qword w = mod(sum[i] - sum[L - 1], Q);
set<qword>::iterator it = s.upper_bound(w);
if (it != s.begin()) --it;
ans = min(ans, mod(w - *it, Q));
s.insert(w);
}
cout << ans << endl;
}
} #define OK int main() {
#ifdef OK
freopen("seq.in","r",stdin);
freopen("seq.out","w",stdout);
ios::sync_with_stdio(0);
#endif // OK
Init();
if(n <= 100000 && m<=10000) work();
else solve();
}

小奇会地球

题意

给一个有负边的n个点的图,如果能给全图边权同时加上(或减去)一个值t,问图中1到n的最短路距离非负时的最小距离。

题目解析

首先跑有负边图的最短路只能SPFA。

由于t和答案同增同减,具有单调性。我们可以二分t来取符合条件的最小距离。

如果通过负环不能到达n号点,这个负环实际上可以忽略。

所以开头建反边,从n跑dfs看能到达哪些点,只对这些点跑最短路即可。

复杂度\(O(Tn^2logt)\)

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue> #define rep(i,s,t) for(int i = (int)(s); i <= (int)(t); ++ i)
#define seta(a,x) memset (a, x, sizeof (a))
#define tral(i) for(int i=h[u];i+1;i=e[i].nxt)
typedef long long qword; using namespace std; const int mod=1e9+7,N=305; struct Edge{int to,nxt,w;}e[N*N];
struct dat{int u,v,w;}a[N*N];
int h[N],n,m,cnt,dis[N],mn,mx,num[N];
bool vis[N],viss[N]; queue<int> Q; inline void add( int u, int v, int w){e[++cnt]=(Edge){v,h[u],w};h[u]=cnt;} inline int SPFA(int x) {
rep(i,1,n) dis[i] = 1e9, num[i] = 0, vis[i] = 0;
while(!Q.empty()) Q.pop();
Q.push(1); vis[1] = 1; dis[1] = 0;
while(!Q.empty()) {
int u=Q.front();Q.pop();
tral(i) {
int v = e[i].to;
if(!viss[v]) continue;
if(dis[v] > dis[u]+e[i].w+x) {
if((++num[v]) > n) return -1e9;
dis[v] = dis[u]+e[i].w+x;
if(!vis[v]) vis[v] = 1, Q.push(v);
}
}
vis[u] = 0;
}
return dis[n];
}
inline void dfs(int u) {
viss[u] = 1;
tral(i) {
int v = e[i].to;
if(viss[v]) continue;
dfs(v);
}
}
int main() {
int T;
cin >> T;
while(T--) {
seta(h, -1);
cnt = 0; mn = 1e9; mx = -1e9;
cin >> n >> m;
rep(i,1,m) {
cin >> a[i].u >> a[i].v >>a[i].w;
add(a[i].v, a[i].u, a[i].w);
mn = min(mn, a[i].w); mx = max(mx, a[i].w);
}
dfs(n);
seta(h, -1); cnt = 0;
rep(i,1,m) add(a[i].u, a[i].v, a[i].w);
if(SPFA(-mn + 100) == 1e9) {cout << "-1" << endl;continue;}
int l = -mx, r = -mn, ans = 0;
while(l <= r) {
int mid = l+r >> 1, check = SPFA(mid);
if(check >= 0) ans = check,r = mid-1;
else l = mid+1;
}
cout << ans << endl;
}
return 0;
}

2015-9-13 NOIP模拟赛 by hzwer的更多相关文章

  1. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  2. NOIP模拟赛(by hzwer) T2 小奇的序列

    [题目背景] 小奇总是在数学课上思考奇怪的问题. [问题描述] 给定一个长度为 n 的数列,以及 m 次询问,每次给出三个数 l,r 和 P, 询问 (a[l'] + a[l'+1] + ... + ...

  3. NOIP模拟赛(by hzwer) T3 小奇回地球

    [题目背景] 开学了,小奇在回地球的路上,遇到了一个棘手的问题. [问题描述] 简单来说,它要从标号为 1 的星球到标号为 n 的星球,某一些星球之间有航线. 由于超时空隧道的存在,从一个星球到另一个 ...

  4. NOIP模拟赛(by hzwer) T1 小奇挖矿

    [题目背景] 小奇要开采一些矿物,它驾驶着一台带有钻头(初始能力值 w)的飞船,按既定 路线依次飞过喵星系的 n 个星球. [问题描述] 星球分为 2 类:资源型和维修型. 1. 资源型:含矿物质量 ...

  5. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  6. NOIP模拟赛 篮球比赛2

    篮球比赛2(basketball2.*) 由于Czhou举行了众多noip模拟赛,也导致放学后篮球比赛次数急剧增加.神牛们身体素质突飞猛进,并且球技不断精进.这引起了体育老师彩哥的注意,为了给校篮球队 ...

  7. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  8. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  9. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

随机推荐

  1. nexus 增加代理仓库 无法搜到snapshot的jar包 解决方法

    如题, nexus 私服 增加了另一个 私服,  但是无法搜到 版本中带有 snapshot字样的 jar包. 环境情况: 1.老私服: 首先版本中带有 snapshot字样的 jar包,是发布在 老 ...

  2. element.style{}

    有时在写css样式,并调试时,会出现很不可思议的现象,比如:我们定义了一个<div class=”aaa”></div>,在css中定义样式,.aaa{width:500px; ...

  3. bootstrap之

    一.字体图标 <button type="button" class="btn btn-primary btn-lg"> <span clas ...

  4. 【原创】asp.net内部原理(三) 第三个版本 (最详细的版本)

    前言: 今天继续吧这个系列补齐,这几天公司的项目比较忙,回到家已经非常的累了,所以也没顾得上天天来这里分享一些东西和大家一起探讨,但是今天晚上我还是坚持打开电脑,分享一些asp.net生命周期的知识, ...

  5. 【算法】N Queens Problem

    /* ** 目前最快的N皇后递归解决方法 ** N Queens Problem ** 试探-回溯算法,递归实现 */ #include "stdafx.h" #include & ...

  6. js中的颜色对应的常量代码code

    颜色的对照表 颜色 英文代码 形像颜色 HEX格式 RGB格式   LightPink 浅粉红 #FFB6C1 255,182,193   Pink 粉红 #FFC0CB 255,192,203   ...

  7. mysql如何查询日期的列表?

    转自:http://blog.csdn.net/liufei198613/article/details/72643345 select @num:=@num+1,date_format(adddat ...

  8. Swift - 多线程GCD详解

    //  GCD详解 //  目录: //  1. 创建GCD队列(最常用) //  2. 自定义创建队列 //  3. 使用多线程实现延迟加载 //  4. 使用多线程实现重复(循环) //  5. ...

  9. MariaDB登陆

    设置root密码 “mariabd”是新密码 [root@master /]# mysqladmin -u root password mariadb [root@master /]# mysql - ...

  10. 如何用css给input的placeholder设置颜色

    我在做页面的时候遇到过这种情况,在input标签中有默认字,但是设计稿上的颜色和input标签中的placeholder的默认颜色不一致.虽然我们可以在js中写出,但是有点过于麻烦了. 所以我就用cs ...