前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率。

结果后面2题都由波神做掉,学长带我们飞~

终榜 官方题解

 

ZOJ 3946 Highway Project(K题)

题意:求到所有点最短花费时间总和以及在这前提下的走过的路的最小花费金钱

分析:首先最短路跑一个,然后在d[v] == d[u] + time的一些边上选择最小金钱,注意这里只要cost[v] = cost不用累加cost[u]。就是跑了两次最短路。

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
struct Edge {
int v, t, c, nex;
};
Edge edge[N<<1];
int head[N];
ll _time[N];
int cost[N];
bool vis[N];
int n, m, tote; void SPFA(int s, ll &sumt, ll &sumc) {
memset (vis, false, sizeof (vis));
memset (_time, INF, sizeof (_time));
vis[s] = true; _time[s] = 0;
std::queue<int> que; que.push (s);
while (!que.empty ()) {
int u = que.front (); que.pop ();
vis[u] = false;
for (int i=head[u]; ~i; i=edge[i].nex) {
Edge &e = edge[i];
if (_time[e.v] > _time[u] + e.t) {
_time[e.v] = _time[u] + e.t;
if (!vis[e.v]) {
vis[e.v] = true;
que.push (e.v);
}
}
}
}
memset (vis, false, sizeof (vis));
memset (cost, INF, sizeof (cost));
vis[s] = true; cost[s] = 0;
que.push (s);
while (!que.empty ()) {
int u = que.front (); que.pop ();
vis[u] = false;
for (int i=head[u]; ~i; i=edge[i].nex) {
Edge &e = edge[i];
if (_time[e.v] == _time[u] + e.t && cost[e.v] > e.c) {
cost[e.v] = e.c;
if (!vis[e.v]) {
vis[e.v] = true;
que.push (e.v);
}
}
}
}
for (int i=1; i<n; ++i) {
sumt += _time[i];
sumc += cost[i];
}
} void add_edge(int u, int v, int t, int c) {
edge[tote].v = v; edge[tote].t = t; edge[tote].c = c;
edge[tote].nex = head[u]; head[u] = tote++;
} void init_edge() {
memset (head, -1, sizeof (head));
tote = 0;
} int test() {
return 10;
} int main() {
std::cerr << test () << '\n';
int T; scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
init_edge ();
for (int i=0; i<m; ++i) {
int u, v, t, c;
scanf ("%d%d%d%d", &u, &v, &t, &c);
add_edge (u, v, t, c);
add_edge (v, u, t, c);
}
ll sumt = 0, sumc = 0;
SPFA (0, sumt, sumc);
printf ("%lld %lld\n", sumt, sumc);
}
return 0;
}

ZOJ 3939 The Lucky Week(D题)

题意:Monday是1日或11日或21日的那天是lucky week day,给了开始日期,问从该天起第N天是哪天。(波神一开始就说是循环节,我一听是循环节感觉很陌生,一脸懵逼,当时还看错题意,Monday还看漏了,赛后补了,发现还是很好做的。)

分析:打表找规律,发现400年一个周期,一个周期有2058天lucky day。对于询问只要取模一下,再400乘回来就行了。

#include <bits/stdc++.h>

typedef long long ll;
int _month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool judge(int y) {
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
return true;
} else {
return false;
}
} struct Data {
int y, m, d;
};
std::vector<Data> vec; void init() {
int day = 1;
//从注释的代码得知只要处理出400年的循环节
for (int i=1753; i<=1753+399; ++i) {
for (int j=1; j<=12; ++j) {
int mday = _month[j];
if (judge (i) && j == 2) {
mday++;
}
while (day <= mday) {
if (day == 1 || day == 11 || day == 21) {
vec.push_back ((Data) {i, j, day});
}
day += 7;
}
day -= mday;
}
}
//calc
/*
for (int i=0; i<vec.size (); ++i) {
bool flag = true;
for (int l=0, r=i+1; l<=i && r<vec.size (); ++l, ++r) {
if (vec[l].m != vec[r].m || vec[l].d != vec[r].d) {
flag = false;
break;
}
}
if (flag) {
printf ("i: %d\n", i); //i + 1 = 2058个luky day
//从以下得知循环节是400年
printf ("[%d,%d,%d]\n", vec[0].y, vec[0].m, vec[0].d);
printf ("[%d,%d,%d]\n", vec[i+1].y, vec[i+1].m, vec[i+1].d);
printf ("[%d,%d,%d]\n", vec[2*i+2].y, vec[2*i+2].m, vec[2*i+2].d);
return ;
}
}
*/
} int main() {
init ();
int T; scanf ("%d", &T);
while (T--) {
int y, m, d; scanf ("%d%d%d", &y, &m, &d);
int n; scanf ("%d", &n);
int sz = vec.size (); //2058
int ady = 0; //add year 1
while (y >= 1753 + 400) {
y -= 400;
ady++;
}
ady += (n - 1) / sz; //add year 2
int add = (n - 1) % sz;
ll ty = y, tm = m, td = d;
for (int i=0; i<sz; ++i) {
if (y == vec[i].y && m == vec[i].m && d == vec[i].d) {
int ti = i + add;
while (ti >= sz) {
ti -= sz;
ady++;
}
ty = vec[ti].y + 1ll * ady * 400;
tm = vec[ti].m;
td = vec[ti].d;
break;
}
}
printf ("%lld %lld %lld\n", ty, tm, td);
}
return 0;
}

  

The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)的更多相关文章

  1. The 13th Zhejiang Provincial Collegiate Programming Contest - D

    The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the headmaster of the Marja ...

  2. ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA

    ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the ...

  3. The 13th Zhejiang Provincial Collegiate Programming Contest - I

    People Counting Time Limit: 2 Seconds      Memory Limit: 65536 KB In a BG (dinner gathering) for ZJU ...

  4. The 13th Zhejiang Provincial Collegiate Programming Contest - C

    Defuse the Bomb Time Limit: 2 Seconds      Memory Limit: 65536 KB The bomb is about to explode! Plea ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...

  6. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)

    Floor Function Time Limit: 10 Seconds      Memory Limit: 65536 KB a, b, c and d are all positive int ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

随机推荐

  1. java获得本机IP,名称等

    import java.net.InetAddress; import java.net.UnknownHostException; public class GetLocalIP { public ...

  2. OSG快速生成一个带有纹理的四边形Geometry

    可以使用Geometry头文件中的 Geometry* createTexturedQuadGeometry osg::ref_ptr<osg::Texture2D> texture = ...

  3. Target runtime Apache Tomcat v6.0 is not defined.错误解决方法

    一.背景 最近在使用本地的tomcat进行运行项目的时候,发现出现了如题所述的问题.不知道什么原因,经过努力解决了该问题. 二.解决步骤 右击项目---选择属性---选择targeted runtim ...

  4. swift枚举

    以下是指南针四个方向的一个例子:  enum CompassPoint { case North case South case East case West }   多个成员值可以出现在同一行上,用 ...

  5. ssh-keygen详解

    先来一段google wiki关于ssh key的解释,对应的连接为:https://wiki.archlinux.org/index.php/SSH_keys_(%E7%AE%80%E4%BD%93 ...

  6. android的JNI 、 NDK 学习!

    转载的! Java Native Interface (JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互.JNI 是本地编程接口,它使得在 Java 虚拟机 (VM) ...

  7. iOS - 定制多样式二维码

    二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息.   最常见的二维码功能包括信息获取.网 ...

  8. 按键消抖-----verilog

    实际系统中常用的按键大部分都是轻触式按键,如下图所示.该按键内部由一个弹簧片和两个固定触点组成,当弹簧片被按下,则两个固定触点接通,按键闭合.弹簧片松开,两个触点断开,按键也就断开了.根据这种按键的机 ...

  9. 与你相遇好幸运,CentOS 7 x86_64使用Yum安装PostgreSQL

    访问http://yum.pgrpms.org/reporpms/repoview/letter_p.group.html,下载并安装和当前系统对应的rpm文件. wget https://downl ...

  10. pthread_create传递参数

    转自:http://blog.csdn.net/yeyuangen/article/details/6757525 #include <iostream> #include <pth ...