2020ICPC·小米 网络选拔赛第一场

先贴一份代码,之后再来写~~(咕)~~

A Intelligent Warehouse

三.代码实现

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int M = (int)2e5;
const int N = (int)1e7;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)998244353;

int n, a[M + 5];
int m, b[M + 5];
int cnt[N + 5];
int f[N + 5];

inline int read()
{
    
    
    int x = 0, f = 1;
    char ch = getchar();
    while(!isdigit(ch))
    {
    
    
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch))
    {
    
    
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

inline void work()
{
    
    
    n = read();
    for(int i = 1; i <= n; ++i) a[i] = read(), cnt[b[i] = a[i]]++;
    sort(b + 1, b + n + 1); m = unique(b + 1, b + n + 1) - (b + 1);

    for(int i = 1; i <= b[m]; ++i) f[i] = cnt[i];

    int ans = 0;
    for(int i = 1; i <= m; ++i)
    {
    
    
        for(int j = 2 * b[i]; j <= b[m]; j += b[i])
        {
    
    
            if(!f[j] || f[b[i]] + cnt[j] <= f[j]) continue;
            f[j] = f[b[i]] + cnt[j];
        }
    }
    for(int i = 1; i <= b[m]; ++i) ans = max(ans, f[i]);
    printf("%d\n", ans);
//    cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
}

int main()
{
    
    
//    cout << (sizeof(is_prime) + sizeof(prime) + sizeof(v) + sizeof(f)) / 1024 << endl;
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    work();
//    int T; scanf("%d", &T);
//    while(T--) work();
    return 0;
}

B Intelligent Robot

/*************************************************************************
    > File Name: solve.cpp
    > Author: XeroxAuto
    > Mail: [email protected]
    > Created Time: 2020-10-25 15:49:10
 ************************************************************************/

#define GOODOJ
#define SYNC 0

#ifdef GOODOJ
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <chrono>
#include <random>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#else
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
#include <limits>
#include <cassert>
#include <sstream>
#include <iterator>
#include <functional>
#endif
using namespace std;

#define endl '\n'
#define fep(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rap(i,x) for(auto& i : (x))
#define seg(t) (t).begin(), (t).end()
#define ep emplace_back
#define mkp make_pair
#define qxx(i,x) for(int i = head[x]; ~i; i = node[i].nex)
#define F first
#define S second
#define lowbit(x) ((-(x))&(x))
#define RE register
#define getchar() getchar_unlocked()
#ifdef DEBUG
void err(istream_iterator<string>){
    
    }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    
    
	cerr << *it << " = " << a << ' ';
	err(++it, args...);
}
#define debug(args...) {string _s=#args;replace(seg(_s),',',' ');\
cerr<<"DEBUG:";istringstream it(_s);\
err(istream_iterator<string>(it), args);cerr<<endl;}
#else
#define debug(...)
#endif

template<typename T> inline bool cmax(T& a,const T& b) {
    
    return a<b?a=b,1:0;}
template<typename T> inline bool cmin(T& a,const T& b) {
    
    return a>b?a=b,1:0;}

#ifdef GOODOJ
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
typedef __gnu_pbds::priority_queue<int> pq;
#endif
typedef std::string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pa;

const int Ma = 630, inf = 0x3f3f3f3f, mod = 1e9 + 7;


typedef Geo::Point point;
typedef Geo::Line line;
typedef Geo::Circle circle;
function<int(db)> sign = Geo::sign;
function<int(db,db)> cmp = Geo::cmp;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
point pt[Ma * 2]; int cnt = 0;
db dis[Ma * 2][Ma * 2]; int k;

bool ck(int u, int v) {
    
    
	line val(pt[u], pt[v]);
	rep (i, k) {
    
    
		if (Geo::checkSS(line(pt[i * 2 + 1], pt[i * 2 + 2]), val, false)) return false;
	}
	return true;
}

bool vis[Ma];

db df[Ma];

db dij(int s, int T) {
    
    
	__gnu_pbds::priority_queue<pair<db, int> > q;
	fep (i, 0, cnt) df[i] = linf;
	df[s] = 0;
	q.push(mkp(0, s));
	while (!q.empty()) {
    
    
		auto t = q.top(); q.pop();
		if (vis[t.S]) continue;
		if (t.S == T) return df[T];
		vis[t.S] = true;
		for (int i = 0; i < cnt; i++) if (!vis[i] and
				                          df[i] > df[t.S] + dis[t.S][i]) {
    
    
			df[i] = df[t.S] + dis[t.S][i];
			q.push(mkp(-df[i], i));
		}
	}
	return df[T];
}

signed main() {
    
    
	#if SYNC==1
    ios::sync_with_stdio(false);
    cin.tie(0);
    #endif
	int n, m; scanf("%d%d%d", &n, &m, &k);
	cnt = 1;
	rep (i, k) pt[cnt++].scan(), pt[cnt++].scan();
	pt[0].scan(); pt[cnt++].scan();
	rep (i, cnt) fep (j, 1, cnt) {
    
    
		if (ck(i, j)) dis[i][j] = dis[j][i] = pt[i].dis(pt[j]);
		else dis[i][j] = dis[j][i] = linf;
	}
	printf("%.4f\n", dij(0, cnt - 1));
    
    return 0;
}

C Smart Browser

s = input()
if s[-1] == 'w' :
    s += 'v'
cnt = 0
ans = 0
for i in s :
    if i == 'w' :
        cnt += 1
    elif cnt :
        ans += cnt + cnt - 1
        cnt = 0
print(ans)

D Router Mesh

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=300000+10;
int n,m;
vector<int> G[maxn];
int cut[maxn];
int low[maxn];
int pre[maxn];
int dfs_clock;
int tarjan(int u,int fa)
{
    
    
    int lowu= pre[u]=++dfs_clock;
    for(int i=0;i<G[u].size();i++)
    {
    
    
        int v=G[u][i];
        if(!pre[v])
        {
    
    
            int lowv=tarjan(v,u);
            lowu=min(lowv,lowu);
            if(lowv>=pre[u]) cut[u]++;
        }
        else if(pre[v]<pre[u] && v!=fa)
            lowu = min(lowu,pre[v]);
    }
    return low[u]=lowu;
}
int main()
{
    
    
    while(scanf("%d%d",&n,&m)==2&&n)
    {
    
    
        dfs_clock=0;
        memset(cut,0,sizeof(cut));
        memset(pre,0,sizeof(pre));
        for(int i=0;i<n;i++) G[i].clear();
        for(int i=0;i<m;i++)
        {
    
    
            int u,v;
            scanf("%d%d",&u,&v);
            u--,v--;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        int sum=0;//计数连通分量数目
        int max_cut=-10000;
        for(int i=0;i<n;i++)if(!pre[i])
        {
    
    
            sum++;
            tarjan(i,-1);
            cut[i]--;
        }
        for(int i=0;i<n;i++){
    
    
            if(i) printf(" ");
            printf("%d",sum+cut[i]);
        }
        printf("\n");
    }
    return 0;
}

I Walking Machine

/*************************************************************************
    > File Name: solve.cpp
    > Author: XeroxAuto
    > Mail: [email protected]
    > Created Time: 2020-10-25 12:13:17
 ************************************************************************/

#define GOODOJ
#define SYNC 0

#ifdef GOODOJ
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <chrono>
#include <random>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#else
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
#include <limits>
#include <cassert>
#include <sstream>
#include <iterator>
#include <functional>
#endif
using namespace std;

#define endl '\n'
#define fep(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rap(i,x) for(auto& i : (x))
#define seg(t) (t).begin(), (t).end()
#define ep emplace_back
#define mkp make_pair
#define qxx(i,x) for(int i = head[x]; ~i; i = node[i].nex)
#define F first
#define S second
#define lowbit(x) ((-(x))&(x))
#define RE register
#define getchar() getchar_unlocked()
#ifdef DEBUG
void err(istream_iterator<string>){
    
    }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    
    
	cerr << *it << " = " << a << ' ';
	err(++it, args...);
}
#define debug(args...) {string _s=#args;replace(seg(_s),',',' ');\
cerr<<"DEBUG:";istringstream it(_s);\
err(istream_iterator<string>(it), args);cerr<<endl;}
#else
#define debug(...)
#endif

template<typename T> inline bool cmax(T& a,const T& b) {
    
    return a<b?a=b,1:0;}
template<typename T> inline bool cmin(T& a,const T& b) {
    
    return a>b?a=b,1:0;}

#ifdef GOODOJ
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
typedef __gnu_pbds::priority_queue<int> pq;
#endif
typedef std::string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pa;

const double P = acos(-1.0), eps = 1e-9;
struct point {
    
     db x ,y;};
inline int sign(db a) {
    
    return a < -eps ? -1 : a > eps;}
#define dot(p1,p2,p3) ((p2.x-p1.x)*(p3.x-p1.x)+(p2.y-p1.y)*(p3.y-p1.y))
#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))

const int Ma = 1e3 + 100, inf = 0x3f3f3f3f, mod = 1e9 + 7;

char mz[Ma][Ma]; int vis[Ma][Ma]; bool can[Ma * Ma];

int xz[] = {
    
    -1, 1, 0, 0},
	yz[] = {
    
    0, 0, -1, 1};
int ax[Ma], n, m, ans;

bool out(int r, int c) {
    
    
	return r < 0 or r >= n or c < 0 or c >= m;
}

void dfs(int i, int j, int pre, int id) {
    
    
	int di = ax[mz[i][j]];
	int ti = i + xz[di], tj = j + yz[di];
	vis[i][j] = id;
	if (out(ti, tj)) ans += pre + 1, can[id] = true;
	else {
    
    
		if (!vis[ti][tj]) dfs(ti, tj, pre + 1, id);
		else if (can[vis[ti][tj]]) ans += pre + 1, can[id] =true;
	}
}

signed main() {
    
    
	#if SYNC==0
    ios::sync_with_stdio(false);
    cin.tie(0);
    #endif
	ans = 0;
	ax['S'] = 1; ax['A'] = 2;
	ax['W'] = 0; ax['D'] = 3;
	cin >> n >> m;
	rep (i, n) cin >> mz[i];
	int cnt = 1;
	rep (i, n) rep (j, m) if (!vis[i][j]) {
    
    
		dfs(i, j, 0, cnt++);
	}
	cout << ans << endl;
    
    return 0;
}

J Matrix Subtraction

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int M = (int)1e3;
const int N = (int)1e7;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)998244353;

int n, m, a, b;

ll s[M + 5][M + 5];
ll d[M + 5][M + 5];

void work()
{
    
    
    scanf("%d %d %d %d", &n, &m, &a, &b);
    for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) scanf("%d", &s[i][j]), d[i][j] = 0;
    for(int i = 1; i <= n; ++i)
    {
    
    
        for(int j = 1, x; j <= m; ++j)
        {
    
    
            d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
            x = s[i][j] + d[i][j];
            if(x == 0) continue;
            else if(x < 0)
            {
    
    
                puts("QAQ");
                return;
            }
            else if(x > 0)
            {
    
    
                if(i + a - 1 > n || j + b - 1 > m)
                {
    
    
                    puts("QAQ");
                    return;
                }
                d[i][j] -= x;
                d[i][j + b] += x;
                d[i + a][j] += x;
                d[i + a][j + b] -= x;
            }
        }
    }
    for(int i = 1; i <= n; ++i)
    {
    
    
        for(int j = 1; j <= m; ++j)
        {
    
    
            if(s[i][j] + d[i][j])
            {
    
    
                puts("QAQ");
                return;
            }
        }
    }
    puts("^_^");
}

int main()
{
    
    
//    cout << (sizeof(is_prime) + sizeof(prime) + sizeof(v) + sizeof(f)) / 1024 << endl;
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    work();
    int T; scanf("%d", &T);
    while(T--) work();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/The___Flash/article/details/109279603