Giter VIP home page Giter VIP logo

ccf-csp-and-pat-solution's Issues

About improve code in this book

in page 14, code of using flag as follows. the ans = 5913.

bool flag = true;
int ans = 0;
for (int i = 1; i <= 10 && flag; ++i)
{
int t = 1;
for (int j = 1; j <= i && flag ; ++j)
{
t *= j;
if (t > 1000) flag = false;
}
ans += t;
}

in page 14, code of using goto as follows. the ans = 873.

int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
if (t > 1000) goto loop;
}
ans += t;
}
loop:;

this is because ans += t; excute more once in first code.
so we can move if statement to behiend the ans += t;
the new code as follwos, the ans = 5913.

int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
}
ans += t;
if (t > 1000) goto loop;
}
loop:;

chncys
email: [email protected]
qq: [email protected]
WeChat ID: cys7749

两处勘误

  1. P428,定义top的时候应该定义成空vector,书上定义成vector<gg> top(MAX)
  2. P436,dijkstra代码中If(dis[p[0] != p[1]),0和1写反了
  3. P371,最下面ggright少了个空格

关于 Dijkstra 算法

请问 Dijkstra 算法中这句代码有什么作用呢?我试了下去掉也能通过。

if (dis[p[1]] != p[0])
    continue;

谢谢🙏

about improve the code in this book

in page 14, code of using flag as follows. the ans = 5913.

bool flag = true;
int ans = 0;
for (int i = 1; i <= 10 && flag; ++i)
{
int t = 1;
for (int j = 1; j <= i && flag ; ++j)
{
t *= j;
if (t > 1000) flag = false;
}
ans += t;
}

in page 14, code of using goto as follows. the ans = 873.

int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
if (t > 1000) goto loop;
}
ans += t;
}
loop:;

this is because ans += t; excute more once in first code.
so we can move if statement to behiend the ans += t;
the new code as follwos, the ans = 5913.

int ans = 0;
for (int i = 1; i <= 10; ++i)
{
int t = 1;
for (int j = 1; j <= i; ++j)
{
t *= j;
}
ans += t;
if (t > 1000) goto loop;
}
loop:;

chncys
email: [email protected]
qq: [email protected]
WeChat ID: cys7749

201403-4错误

13 3 1 3
0 0
5 5
-3 0
-3 2
-3 4
-3 6
-1 7
0 5
3 5
1 -2
3 -2
5 -2
5 1

3 3
4 4
3 0
正确答案是5
提供代码输出为7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.