2019 ICPC Nanchang network game
Match Time: 2019.9.8
game links: at The 2019 Asia Online Programming Contest The Nanchang First Round
to sum up
// once the highest ranking history, opening less than two hours each teammate a title A title a total of four questions, add water, instant ranking rose to three or four ten // then after three hours on the autistic, did not break a problem. . . Finally ranked 211 hhhh
B. Fire-Fighting Hero
The meaning of problems
His teammates do, to be completed.
AC Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 2010;
int head[N],cnt;
struct node
{
int v,nxt,w;
}e[N*N];
void addedge(int u,int v,int w)
{
e[cnt].v= v;
e[cnt].nxt = head[u];
e[cnt].w = w;
head[u] = cnt++;
}
int dis[N];
int mp[N][N];
queue<int>q;
int vis[N];
void spfa()
{
while(!q.empty())
{
int u = q.front();
//cout<<u<<endl;
q.pop();
vis[u] = 0;
for(int i=head[u];~i;i=e[i].nxt)
{
int v = e[i].v;
//cout<<" "<<v<<endl;
if(dis[v]>dis[u]+mp[u][v])
{
dis[v] = dis[u]+mp[u][v];
if(vis[v]==0)
{
q.push(v);
vis[v] = 1;
}
}
}
}
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
memset(head,-1,sizeof(head));
cnt = 0;
int V,E,S,K,C;
scanf("%d%d%d%d%d",&V,&E,&S,&K,&C);
for(int i=1;i<=V;++i)
{
vis[i]=0;
dis[i]=(1<<30);
for(int j=1;j<=V;++j)
mp[i][j]=(1<<30);
}
for(int i=1;i<=K;++i)
{
int d;scanf("%d",&d);
dis[d] = 0;
q.push(d);
vis[d] = 1;
}
for(int i=1;i<=E;++i)
{
int u,v,w;scanf("%d%d%d",&u,&v,&w);
if(mp[u][v]==(1<<30))
{
addedge(u,v,w);
addedge(v,u,w);
}
mp[u][v]=mp[v][u]=min(mp[u][v],w);
}
spfa();
int ptr = 0;
for(int i=1;i<=V;++i)
if(dis[i]!=(1<<30))
ptr = max(ptr,dis[i]);
for(int i=1;i<=V;++i)
{
vis[i] = 0;
dis[i]=(1<<30);
}
dis[S] = 0;
while(!q.empty())q.pop();
q.push(S);
vis[S] = 1;
spfa();
int hero = 0;
for(int i=1;i<=V;++i)
if(dis[i]!=(1<<30))
hero = max(hero,dis[i]);
if(hero<=ptr*C)
printf("%d\n",hero);
else
printf("%d\n",ptr);
}
return 0;
}
E. Magic Master
The meaning of problems
N stack on the table playing cards, each card has a number (1 ~ N), taken out in the following two processes:
- Remove the top of this pile of poker card, into the hands of. There are cards on hand, then put all cards in the bottom.
- If there is remaining cards on the table, put the top of the table in the end of the insertion portion, the operating M times.
If the last hand of cards numbered in descending order, the table began to seek each card number is. Q There are times asked each table from top to bottom of the k-card number is given.
Thinking
Start rough count, like they can be calculated directly simulate the initial number. Finished found that the complexity of the reach \ (O (QN ^ 2) \) , affirmed the T.
Clutching the code did not pay, it was found that only the largest Q 100, then the result is 100 times before only processing of queries, the sample tune for a long time did not run out.
printf
Debugging the first operator found to have a good result, so coupled with the memory of a similar mark. Then pay up to A.
After the game I have a big brother did not say in how to deal with this Josephus, I realized this is Josephus ah, why they do T
I could use the STL queue
very good right O ( ¯ ▽ ¯ ) O
AC Code
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int maxn = 40000010;
int n, m;
int ans[maxn], now;
queue<int> q;
void solve(int k) {
if(ans[k]!=-1) {
printf("%d\n", ans[k]);
return;
}
while(q.size()) {
int num = q.front(); q.pop();
ans[num] = ++now;
bool flag = 0;
if(num==k) {
printf("%d\n", ans[k]);
flag = true;
}
if(q.empty()) break;
for(int i=1;i<=m;i++) {
int num = q.front(); q.pop();
q.push(num);
}
if(flag) break;
}
}
int main() {
int T; cin>>T;
while(T--) {
int Q;
scanf("%d %d %d", &n, &m, &Q);
memset(ans, -1, sizeof(ans));
while(q.size()) q.pop();
for(int i=1;i<=n;i++) q.push(i);
now = 0;
while(Q--) {
int k;
scanf("%d", &k);
solve(k);
}
}
return 0;
}
G. Pangu Separates Heaven and Earth
The meaning of problems
Attendance problems.
AC Code
slightly.
H. The Nth Item
The meaning of problems
Defined
\ [F (0) = 0
, F (1) = 1 \\ F (n) = 3 * F (n-1) + 2 * F (n-2), (n≥2) \] There \ (Q \) times inquiry request \ (F. (N) \) . ( \ (. 1 \ Leq Q \ ^ Leq 10. 7, 0 \ Leq N \ Leq 18 is 10 ^ {} \) )
Thinking
His teammates began to feel BM linear recurrence can do, I happily took a post on the board to change to change TLE.
Then I saw you two do not completely linear recurrence ah, direct matrix power quickly enough.
I fast while writing matrix power, and prompts the intermediate results survive, let teammates find ways to optimize.
Then teammate construct a set of data, but I'm a T handed extrapolated linearly, so he paid the AC.
AC Code
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<ll> VLL;
const ll mod = 998244353;
ll powmod(ll a, ll b) {
ll res=1;a%=mod;
for(;b;b>>=1) {
if(b&1) res=res*a%mod;
a=a*a%mod;
}
return res;
}
namespace linear_seq {
const int N = 100010;
ll res[N], base[N], _c[N], _md[N];
VLL Md;
void mul(ll a[], ll b[], int k) {
for(int i=0;i<k+k;i++)
_c[i] = 0;
for(int i=0;i<k;i++)
if(a[i])
for(int j=0;j<k;j++)
_c[i+j] = (_c[i+j] + a[i]*b[j]%mod) % mod;
for(int i=k+k-1;i>=k;i--)
if(_c[i])
rep(j,0,SZ(Md))
_c[i-k+Md[j]] = (_c[i-k+Md[j]] - _c[i] * _md[Md[j]]%mod) % mod;
for(int i=0;i<k;i++)
a[i] = _c[i];
}
ll solve(ll n, VLL a, VLL b) {
ll ans = 0, pnt = 0;
int k = SZ(a);
for(int i=0;i<k;i++)
_md[k-1-i]=-a[i];
_md[k]=1;
Md.clear();
for(int i=0;i<k;i++)
if(_md[i]!=0) Md.push_back(i);
for(int i=0;i<k;i++)
res[i]=base[i]=0;
res[0]=1;
while((1ll<<pnt)<=n) pnt++;
for(int p=pnt;p>=0;p--) {
mul(res, res, k);
if((n>>p)&1) {
for(int i=k-1;i>=0;i--)
res[i+1]=res[i];res[0]=0;
rep(j,0,SZ(Md))
res[Md[j]]=(res[Md[j]] - res[k]*_md[Md[j]]%mod) % mod;
}
}
for(int i=0;i<k;i++)
ans = (ans + res[i]*b[i]%mod) % mod;
if(ans<0) ans += mod;
return ans;
}
VLL BM(VLL s) {
VLL C(1,1), B(1,1);
int L=0,m=1,b=1;
rep(n,0,SZ(s)) {
ll d=0;
rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i]%mod) % mod;
if(d==0) ++m;
else if(2*L<=n) {
VLL T=C;
ll c=mod-d*powmod(b,mod-2)%mod;
while(SZ(C)<SZ(B)+m) C.pb(0);
rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i]%mod) % mod;
L=n+1-L; B=T; b=d; m=1;
} else {
ll c = mod- d*powmod(b, mod-2)%mod;
while(SZ(C)<SZ(B)+m) C.pb(0);
rep(i,0,SZ(B))
C[i+m]=(C[i+m]+c*B[i]%mod) % mod;
++m;
}
}
return C;
}
};
VLL a, c;
ll fib[110];
void init() {
fib[1] = 1;
for(int i=2;i<110;i++) {
fib[i] = (3*fib[i-1] + 2*fib[i-2]) % mod;
}
for(int i=1;i<=100;i++) {
a.pb(fib[i]);
}
c = linear_seq::BM(a);
c.erase(c.begin());
rep(i,0,SZ(c))
c[i] = (mod-c[i])%mod;
}
map<ll,ll>mp;
int main() {
init();
int T; ll N;
scanf("%d %lld", &T, &N);
ll RES = 0;
ll ans = 0;
while(T--) {
N = (ans*ans)^N;
if(mp[N]) ans = mp[N];
else ans = linear_seq::solve(N-1, c, VLL(a.begin(), a.begin()+SZ(c)));
mp[N]=ans;
RES ^= ans;
// printf("%lld\n", ans);
}
printf("%lld\n", RES);
return 0;
}
/*
卡矩阵快速幂的数据
10000000 473844410
*/
(Unfinished be completed ..)