2019.11.13 solution to a problem report


2019.11.13 solution to a problem report

\ [Beep beep ↗ ↘ ↗ beep beep beep ↗ ↘ ↗ beep beep beep ↗ ↘ beep ↗ \]
\ [\ {By text: UNBLOCK} \]

Answer: The

  • Total score: 160, Ranking: 8/37
  • T1: 100 T2: 60 T3: 0

Each topic analysis:

  • Topic 1:
    Estimated results: 100 Actual score: 100 examinations: 9:02 - 9:51

    Still spent one hour of time to consider each topic, find a beautiful nature,
    the time to write very clear ideas, wrote four heavy violence enumeration, and soon realized, had lost large sample.

  • Problem 2:
    60 examinations:: Estimated results: 60 actual accomplishment 9:55 ~ 10:34

    Consider first 60 minutes of violence, and soon realized, over a large sample.

  • Problem 3:
    Estimated results: 20 Actual Results: Examination by 0: 10: 36 ~ 10:58

    No feeling, wrote some 20 points, there is no time to check, write hung up violence.

    • Lesson: To arrange time to do problems, write as much as possible to ensure violence does not write while hanging
      sure to leave enough time to check

Topic Analysis:

T1:

Can be found, for a point on the circumference, six randomly selected,
the connection between them, there are six kinds of programs
six kinds embodiment only one triangle may be composed of a

Obviously, the answer is C (n, 6)


T2:

60% of the data:

01 using a backpack maintain currency denomination value must be used in each set
using the pressure-shaped array, each of the number of array-like pressure in the presence of 25 positions

Enumeration value when transferring, and to enumerate the current currency denominations updated
state transition equation:
need [J] [K] = & (need [J - A [I]] [K] | (K == POS1? 1 << pos2: 0));

Finally, the output value of the composition required to be currency denomination
complexity of O (x * n)

100% Data:

Set f [i] represents, given currency, the composition value of the number of embodiments i
values using the backpack 01, the processing of the ~ x f [i]. 1 of

After the enumeration of each currency denomination j,
recursively checks constantly subtracting x w [j], is determined F [x] and f [x - w [j] ], f [x - w [j]] and f [x - 2 * w [ j]] .... are equal
if one is found x, satisfying x> 0, and so f [x - w [j] ] = 0, then x must be composed of currency j, started back
to judge whether the denomination currency can be omitted


T3:

Topics requirements:
Given a directed graph, the right side of a side, the right side may be a negative number.
Causes all sides with the plus / minus a number of
requirements 1-> N of a shortest path, so that the smallest non-negative and

20% Data: at most one point of each side of the
rule 1 -> N between the shortest unique
from 1:00 DFS starts, after recording the number of edges and edge weights and passing
through the number of edges, according to the edge weights and conversion of non-negative is the answer

100% Data:

Since the edge weights smaller ranges could be considered the right side half enum modified, and if legitimate
Obviously, if 1-> N shortest path, and a minimum non-negative so,
rule 1 -> not necessarily the shortest path loop negative, and the positive side and the right of

Obviously, the point does not reach n is no contribution
can be carried out by dfs starting from 1, to be able to reach the point n is marked
will not reach the point n deleted to reconstruct the original image

Enumeration answer, whether there is a negative ring using dfs bfs optimized spfa FIG determination / in.
If a negative ring is present, the amount is not valid enumeration.
If 1--> N Right and negative sides, not legitimate


Code:

T1:

  • Examination room Code (positive solutions):
//
/*
By:Luckyblock
*/
#include <cstdio>
#include <ctype.h>
#define ll long long
//=============================================================
ll N, ans;
//=============================================================
inline int read()
{
    int s = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') s = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 1) + (w << 3) + (ch ^ '0');
    return s * w;
}
//=============================================================
int main()
{
    freopen("triangle.in", "r", stdin);
    freopen("triangle.out", "w", stdout);
    N = (ll) read();
    if(N <= 5) {putchar('0'); return 0;}
    for(int l = 6; l <= N; l ++)
      for(int u1 = 1, v1 = 4; v1 <= l - 2; v1 ++)
        for(int u2 = 3; u2 < v1; u2 ++)
          for(int v2 = v1 + 2; v2 <= l; v2 ++)
            ans += (u2 - u1 - 1) * (v2 - v1 - 1);
    printf("%I64d", ans);
}

T2:

  • Examination room Code:
#include <cstdio>
#include <algorithm>
#include <ctype.h>
#define ll long long
const int MARX = 1e5 + 10;
//=============================================================
int N, X, a[MARX], need[MARX][10]; 
int ans[MARX];
//=============================================================
inline int read()
{
    int s = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') s = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 1) + (w << 3) + (ch ^ '0');
    return s * w;
}
//=============================================================
int main()
{
    freopen("coin.in", "r", stdin);
    freopen("coin.out", "w", stdout);
    N = read(), X = read();
    for(int i = 1; i <= N; i ++) a[i] = read();
    
    for(int i = 1; i <= X; i ++)
      for(int j = 1; j <= 8; j ++)
        need[i][j] = (1 << 30) - 1;
    std :: sort(a + 1, a + N + 1);
    
    for(int i = 1; i <= N; i ++)
      for(int j = X; j >= a[i]; j --)
      {
        int pos1 = ((i  - 1)/ 25) + 1, pos2 = i - 25 * (pos1 - 1);
        for(int k = 1; k <= 8; k ++) 
          need[j][k] &= (need[j - a[i]][k] | (k == pos1 ? 1 << pos2 : 0));
      }
    
    for(int i = 1; i <= 8; i ++)
      for(int j = 1; j <= 25; j ++)
        if((1 << j) & need[X][i]) 
          ans[0] ++, ans[ans[0]] = a[25 * (i - 1) + j];
    
    printf("%d\n", ans[0]);
    for(int i = 1; i <= ans[0]; i ++) printf("%d ", ans[i]);
}
  • Correct answer:
#include <cstdio>
#include <cctype>
#include <map>

const int MAXN = 100010;
int f[MAXN] = {1}, coin[MAXN], cnt, Max;
bool mark[MAXN], bucket[MAXN];

inline int read() {
    int s = 1, w = 0; char ch = getchar();
    for(; ! isdigit(ch); ch = getchar()) if(ch == '-') s = -1;
    for(; isdigit(ch); ch = getchar()) w = w * 10 + ch - '0';
    return s * w;
}
inline int max(int a, int b) { return a > b ? a : b; }
int num(int x, int y) { return x < 0 ? 0 : f[x] - num(x - y, y); }

int main() {
//  freopen("coin.in", "r", stdin), freopen("coin.out", "w", stdout);
    int n = read(), x = read();
    for (int i = 1; i <= n; i ++) coin[i] = read(), Max = max(Max, coin[i]);
    for (int i = 1; i <= n; i ++)
      for (int j = x; j >= coin[i]; j --) 
        f[j] += f[j - coin[i]];
    for (int i = 1; i <= n; i ++) 
      if (f[x] - num(x - coin[i], coin[i]) == 0) 
        if (! bucket[coin[i]]) bucket[coin[i]] = 1, cnt ++;
    printf("%d\n", cnt);
    for (int i = 1; i <= Max; i ++) if (bucket[i]) printf("%d ", i);
    return 0;
}
/*
5 18
10 2 3 5 1
*/

T3:

  • Examination room Code:
//
/*
By:Luckyblock
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctype.h>
#include <queue>
#define min std::min
#define max std::max
#define ll long long
const int MARX1 = 110;
const int MARX2 = 1e5 + 10;
const int INF = 1e5 + 10;
//=============================================================
struct edge
{
    int v, w, ne;
}e[MARX2 << 1];
int num, T, N, M, into[MARX1], head[MARX1];
int ans, maxt, mint;
bool flaginto1, vis[MARX1];
//=============================================================
inline int read()
{
    int s = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') s = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 1) + (w << 3) + (ch ^ '0');
    return s * w;
}
void add(int u, int v, int w)
{
    e[++ num].v = v, e[num].w = w;
    e[num].ne = head[u], head[u] = num;
}
void New_begin()
{
    ans = INF, num = 0, maxt = - INF, mint = INF, flaginto1 = 1;
    memset(into, 0, sizeof(into));
    memset(head, 0, sizeof(head));
    
    N = read(), M = read();
    for(int i = 1; i <= M; i ++)
    {
      int u = read(), v = read(), w = read();
      maxt = max(maxt, w), mint = min(mint, w);
      if((++ into[v]) > 1) flaginto1 = 0; 
      add(u, v ,w); 
    }
}
void solveinto1()
{
    int tot = 0, sum = 0;
    for(int u = 1; u != N; u = e[head[u]].v)
    {
      sum += e[head[u]].w, tot ++;
      if(! head[u]) {printf("-1"); return ;}    
    }
    while(sum < 0) sum += tot;
    printf("%d", sum);
}
void dfs(int u, int sum, int tot)
{
    if(u == N) 
    {
      if(sum < 0)
      {
        int tmp1 = - sum, tmp2 = tmp1 / tot;
        sum += tmp2 * tot;
        if(sum < 0) sum += tot; 
      }
      ans = min(ans, sum);
      return;
    }
    for(int i = head[u]; i; i = e[i].ne)
      if(! vis[e[i].v])
      {
        vis[e[i].v] = 1;
        dfs(e[i].v, sum + e[i].w, tot + 1);
        vis[e[i].v] = 0;
      }
}
//=============================================================
int main()
{
    freopen("home.in", "r", stdin);
    freopen("home.out", "w", stdout);
    T = read();
    while(T --)
    {
      New_begin();
      if(flaginto1) {solveinto1(); continue;}
      dfs(1, 0, 0);
      printf("%d", ans < INF ? ans : - 1);
    }
}
  • Correct answer:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#define pa pair<int,int>
#define inf 1000000000
using namespace std;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int T,n,m,cnt,ans,mid;
int last[105],q[105],d[105];
bool mark[105],con[105];
struct data{int to,next,v;}e[200005];
void insert(int u,int v,int w)
{
    e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;e[cnt].v=w;
}
bool dfs(int x)
{
    mark[x]=1;
    for(int i=last[x];i;i=e[i].next)
        if(d[x]+e[i].v+mid<d[e[i].to]&&con[e[i].to])
        {
            if(mark[e[i].to])return 1;
            d[e[i].to]=d[x]+e[i].v+mid;
            if(dfs(e[i].to))return 1;
        }
    mark[x]=0;
    return 0;
}
void spfa()
{
    for(int i=1;i<=n;i++)d[i]=inf;
    int head=0,tail=1;
    q[0]=1;mark[1]=1;d[1]=0;
    while(head!=tail)
    {
        int now=q[head];head++;if(head==100)head=0;
        for(int i=last[now];i;i=e[i].next)
            if(d[now]+e[i].v+mid<d[e[i].to]&&con[e[i].to])
            {
                d[e[i].to]=d[now]+e[i].v+mid;
                if(!mark[e[i].to])
                {
                    mark[e[i].to]=1;
                    q[tail]=e[i].to;tail++;
                    if(tail==100)tail=0;
                }
            }
        mark[now]=0;
    }
}
void dfscon(int x)
{
    mark[x]=1;
    for(int i=last[x];i;i=e[i].next)
        if(!mark[e[i].to])
            dfscon(e[i].to);
}
bool jud()
{
    for(int i=1;i<=n;i++)
        if(con[i])
        {
            for(int j=1;j<=n;j++)d[j]=inf;
            memset(mark,0,sizeof(mark));
            if(dfs(i))return 0;
        }
    spfa();
    if(d[n]>=0&&d[n]!=inf)return 1;
    return 0;
}
int main()
{
    freopen("home.in","r",stdin);
    freopen("home.out","w",stdout);
    T=read();
    while(T--)
    {
        memset(con,1,sizeof(con));
        memset(last,0,sizeof(last));
        cnt=0;ans=-1;
        n=read();m=read();
        for(int i=1;i<=m;i++)
        {
            int u=read(),v=read(),w=read();
            insert(u,v,w);
        }
        memset(mark,0,sizeof(mark));
        dfscon(1);
        for(int i=1;i<=n;i++)if(!mark[i])con[i]=0;
        for(int i=1;i<=n;i++)
            if(con[i])
            {
                memset(mark,0,sizeof(mark));
                dfscon(i);
                if(!mark[n])con[i]=0;
            }
        int l=-100000,r=100000;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(jud())ans=d[n],r=mid-1;
            else l=mid+1;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/luckyblock/p/11852359.html