11.15NOIP模拟赛
11.15NOIP模拟赛
这套题真的是十分简单,还是拿分技巧不够。
T1 小 R 与糖果
考场上因为前缀和自闭了一个小时,发现自己很智障。。
主要就是前缀和的问题,打表发现
注意负数的特判
struct Matrix
{
int a[4][4];
il void init() {memset(a, 0, sizeof(a));}
il Matrix operator * (const Matrix &b) const
{
Matrix c; c.init();
for(int k = 1; k <= 2; ++k)
for(int i = 1; i <= 2; ++i)
for(int j = 1; j <= 2; ++j)
c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j]) % mod;
return c;
}
}A, ans;
int n, k, tmp, maxn1 = -INF, maxn2 = -INF, k1, k2;
il Matrix qpow(Matrix A, int k)
{
Matrix ans = A; k --;
while(k)
{
if(k & 1) ans = ans * A;
A = A * A;
k >>= 1;
}
return ans;
}
il void init(int k)
{
k--;
A.a[1][1] = 1, A.a[1][2] = 1;
A.a[2][1] = 1, A.a[2][2] = 0;
ans.a[1][1] = 1, ans.a[1][2] = 0;
ans.a[2][1] = 0, ans.a[2][2] = 0;
ans = qpow(A, k + 1) * ans;
k1 = ans.a[1][1];
A.a[1][1] = 1, A.a[1][2] = 1;
A.a[2][1] = 1, A.a[2][2] = 0;
ans.a[1][1] = 1, ans.a[1][2] = 0;
ans.a[2][1] = 0, ans.a[2][2] = 0;
ans = qpow(A, k + 2) * ans;
k2 = ans.a[1][1];
}
signed main()
{
freopen("candy.in","r",stdin);
freopen("candy.out","w",stdout);
n = re(), k = re();
for_1(i, n)
{
int x = re();
tmp += x;
tmp = (tmp + mod) % mod;
if(maxn1 < x)
{
maxn2 = maxn1, maxn1 = x;
}else if(x > maxn2) maxn2 = x;
}
if(maxn1 < 0)
{
int tmp1 = maxn1 + maxn2;
tmp = (tmp + tmp1 * (k % mod) % mod) % mod;
cout<<(tmp + mod) % mod<<endl;
return 0;
}else if(maxn1 > 0 and maxn2 < 0)
{
while(maxn2 < 0)
{
tmp = (tmp + maxn1 + maxn2) % mod;
maxn2 = maxn2 + maxn1;
k--;
}
init(k);
tmp -= maxn1 + maxn2;
tmp = (tmp + ((((k2 - 2 + mod) % mod) * (maxn1 + maxn2) % mod + k1 * maxn1 % mod) % mod + 2 * maxn2 % mod) % mod + maxn1 ) % mod;
cout<<(tmp + mod) % mod<<endl;
return 0;
}else
{
init(k);
tmp -= maxn1 + maxn2;
tmp = (tmp + mod) % mod;
tmp = (tmp + ((((k2 - 2 + mod) % mod) * (maxn1 + maxn2) % mod + k1 * maxn1 % mod) % mod + 2 * maxn2 % mod) % mod + maxn1 ) % mod;
cout<<(tmp + mod) % mod<<endl;
return 0;
}
}
/*
5 2
-1 8 -7 -8 -21
*/
T2 小 R 与旅行
并不是很会做,根本没有往 dp 的方面思考啊。(听说费用流也能写这个题?)
我们设 dp 状态
最后的时候为了保证是一个环,还要保证
map<string, int> mp;
int n, m, ans = 1, fl;
int vis[520][520], dis[520][520], f[520][520];
string s, s1, s2;
signed main()
{
freopen("tour.in","r",stdin);
freopen("tour.out","w",stdout);
n = re(), m = re();
for_1(i, n)
{
cin>>s;
mp[s] = i;
}
for(int i = 1; i <= m; ++i)
{
cin>>s1>>s2;
vis[mp[s1]][mp[s2]] = 1, vis[mp[s2]][mp[s1]] = 1;
}
memset(f, 0xcf, sizeof(f));
f[1][1] = 1; vis[1][1] = 1;
for(int i = 1; i <= n; ++i)
{
for(int j = i + 1; j <= n; ++j)
{
for(int k = 1; k <= n; ++k)
{
if(j == k) continue;
if(vis[j][k])
f[i][j] = f[j][i] = max(f[i][j], f[i][k] + 1);
}
}
}
for(int i = 1; i <= n; ++i)
{
if(vis[i][n]) ans = max(ans, f[i][n]);
}
cout<<ans<<endl;
}
/*
8 9
Vancouver
Yellowknife
Edmonton
Calgary
Winnipeg
Toronto
Montreal
Halifax
Vancouver Edmonton
Vancouver Calgary
Calgary Winnipeg
Winnipeg Toronto
Toronto Halifax
Montreal Halifax
Edmonton Montreal
Edmonton Yellowknife
Edmonton Calgary
*/
T3 小 R 与 b 图
就很傻,很水的一个题啊,就是脑子瓦特了。。
考虑从终点向别的点跑,那么最终状态是确定的,所以编号为 1 的边的计算式就是
struct e {int x, y, z, id;} e[N];
int n, m, ans1, ans2;
int dis[200], v[200], vis[N], a[N];
int head[N], ver[N], nxt[N], tot, edge[N];
il void add(int x, int y, int z) {ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; edge[tot] = z;}
il void dij(int s)
{
priority_queue<pa, vector<pa>, greater<pa> > q;
memset(dis, 0x3f, sizeof(dis));
memset(v, 0, sizeof(v));
dis[s] = a[s]; q.push(mp(dis[s], s));
while(q.size())
{
int x = q.top().second; q.pop();
if(v[x]) continue;
v[x] = 1;
for_edge(i, x)
{
int y = ver[i], z = edge[i];
if(vis[i]) continue;
if(z == 1)
{
if(dis[y] > dis[x] + 1)
{
dis[y] = dis[x] + 1;
q.push(mp(dis[y], y));
}
}
else
{
int now = (dis[x] + 18) / 19;
if(dis[y] > dis[x] + now)
{
dis[y] = dis[x] + now;
q.push(mp(dis[y], y));
}
}
}
}
}
signed main()
{
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
n = re(), m = re();
for_1(i, n) a[i] = re();
for_1(i, m)
{
int x = re(), y = re(), op = re();
if(op == 0)
{
add(x, y, 1); add(y, x, 1);
e[i].id = tot;
}else
{
add(x, y, 0); add(y, x, 0);
e[i].id = tot;
}
}
for(int i = 1; i <= n; ++i)
{
dij(i);
for(int j = 1; j <= n; ++j)
ans1 += dis[j];
}
for(int i = 1; i <= m; ++i)
{
vis[e[i].id] = vis[e[i].id - 1] = 1; int fl = 0, tmp = 0;;
for(int j = 1; j <= n; ++j)
{
dij(j);
for(int k = 1; k <= n; ++k)
{
if(dis[k] == INF) {fl = 1; break;}
tmp += dis[k];
}
if(fl) break;
}
vis[e[i].id] = vis[e[i].id - 1] = 0;
if(fl) continue;
ans2 = max(ans2, tmp);
}
cout<<ans1<<" "<<ans2<<endl;
}
/*
4 5
5 4 3 2
1 2 0
2 3 0
3 4 0
2 4 0
1 4 0
*/
努力奔跑吧