APAC 2013 部分题解 | 训练记录

Posted PushyTao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了APAC 2013 部分题解 | 训练记录相关的知识,希望对你有一定的参考价值。

目录

A . The Alphabet Sticker

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int main()
    int _;cin>>_;
    while(_--)
        string s;cin>>s;
        ll l=0,r=s.size()-1;
        while(s[l]=='?') l++;
        while(s[r]=='?') r--;
        ll ans=1ll,tmp=0;
        for(int i=l;i<=r;i++)
            if(s[i]=='?')
                tmp=i;
                while(s[tmp]=='?') tmp++;
                ll now=tmp-i+1;
                if(s[i-1]!=s[tmp]) ans=ans*now%mod;
                i=tmp;
            
        
        cout<<ans<<endl;
    
    return 0;

C . Increasing Shortest Path

排序升序加边跑dp

/*** keep hungry and calm PushyTao!***/

struct node 
    int u, v, w;
    friend bool operator<(node a, node b)  return a.w < b.w; 
 e[3007];
int dp[157][157][157];
int mp[157][157];
int main() 
    int _ = read;
    while (_--) 
        int n = read, m = read, q = read;
        memset(mp, 0x3f3f3f3f, sizeof mp);
        for (int i = 1; i <= m; i++) 
            // int u = read, v = read, w = read;
            // mp[u][v] = min(mp[u][v], w);
            e[i].u = read, e[i].v = read, e[i].w = read;
        
        /**
        int idx = 0;
        for (int i = 1; i <= n; i++) 
            for (int j = 1; j <= n; j++) 
            	if(mp[i][j] < 0x3f3f3f3f) 
            		idx ++;
            		e[idx].u = i;
            		e[idx].v = j;
            		e[idx].w = mp[i][j];
            	
            
        
        **/
        sort(e + 1, e + 1 + m);
        memset(dp, 0x3f3f3f3f, sizeof dp);
        for (int i = 1; i <= n; i++) dp[i][i][0] = 0; //自己到自己的距离是0
        for (int i = 1; i <= m; i++) 
            for (int qi = 1; qi <= n; qi++) 
                for (int skp = 1; skp <= n - 1; skp++)  // len max n-1
                    dp[qi][e[i].v][skp] = min(dp[qi][e[i].v][skp], dp[qi][e[i].u][skp - 1] + e[i].w);
                
            
        
        while (q--) 
            int x = read, y = read, c = read;
            c       = min(c, n - 1);
            itn ans = 0x3f3f3f3f;
            for (int i = 0; i <= c; i++) ans = min(ans, dp[x][y][i]);
            if (ans == 0x3f3f3f3f)
                puts("-1");
            else
                printf("%d\\n", ans);
        
    
    return 0;

/**
1
8 9 3
1 2 1
2 3 2
3 4 3
4 5 12
5 8 7
1 6 8
6 4 9
1 7 5
7 4 4
1 4 2
1 4 3
1 4 1

**/

D . Cup of Cowards

#include <bits/stdc++.h>

typedef long long ll;

#pragma region Debug
template<typename T>
std::istream& operator>> (std::istream& in, std::vector<T>& vt)

	for (auto& i : vt) in >> i;
	return in;

template<typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& vt)

	for (auto& i : vt) out << i << " ";
	out << std::endl;
	return out;

void printAll()   
template<typename T1, typename... T2>
void printAll(const T1& first, const T2&... second)

	std::cout << first;
	if (sizeof...(second)) 
		std::cout << ", ";
	
	printAll(second...);

template<typename T1, typename... T2>
void print(const T1& first, const T2&... second)

	std::cout << "[";
	printAll(first, second...);
	std::cout << "]" << std::endl;

#pragma endregion

#define N (int)(5e2 + 10)

struct Node 
	int h;
	long long d, c;

	friend bool operator< (Node& A, Node& B)
	
		if (A.d * B.c != B.d * A.c) 
			return A.d * B.c > B.d * A.c;
		
		return A.c < B.c;
	
;

long long L;
long long sufDam[N];
std::vector<Node> v(5);

long long cost, dam;

void dfs(int dep, ll curCost, ll curDam) 
	if (curDam >= L) 
		if (curCost < cost) 
			cost = curCost;
			dam = curDam;
		
		else if (curCost == cost) 
			dam = std::min(dam, curDam);
		
		return;
	
	if (dep == 5) return;
	if (curDam + sufDam[dep] < L) return;

	ll rouDam = L - curDam;
	ll cnt = (rouDam + (v[dep].d - 1)) / v[dep].d;

	if ((cnt - 1) * v[dep].c + curCost > cost) return;
	if (cnt > v[dep].h) cnt = v[dep].h;

	for (int j = cnt; j >= 0; j--) 
		dfs(dep + 1, curCost + 1LL * j * v[dep].c, curDam + 1LL * j * v[dep].d);
	


int main()

	int T;
	std::cin >> T;

	while (T--) 
		std::cin >> L;
		for (auto& [h, d, c] : v) 
			std::cin >> h >> d >> c;
		

		sort(v.begin(), v.end());

		sufDam[4] = 1LL * v[4].h * v[4].d;
		for (int i = 3; i >= 0; i--) 
			sufDam[i] = sufDam[i + 1] + 1LL * v[i].h * v[i].d;
		

		cost = LLONG_MAX, dam = LLONG_MAX;
		dfs(0, 0, 0);

		if (cost == LLONG_MAX) 
			std::cout << "We are doomed!!" << std::endl;
		
		else 
			std::cout << cost << " " << dam << std::endl;
		
	
	return 0;


/*
2 3 4
3 1 2
2 3 2

31 15

D题题意:

输入
T
L
五组H, D, C

L表示怪物的总血量
五个玩家
H表示当前玩家可以攻击的次数限制
D表示每次攻击造成的伤害
C表示花费

问杀死怪物的最小花费和最小伤害


*/

E . Balloons Colors

int a[107];
int main() 
	int _ = read;
	while(_--) 
		int n = read;
		a[1] = read,a[n] = read;
		int f1 = 0, f2 = 0;
		for(int i=1;i<=n;i++) 
			int x = read;
			if(x == a[1] && i == 1) f1 = 1;
			if(x == a[n] && i == n) f2 = 1;
		
		if(f1 && f2) puts("BOTH");
		else if(f1) puts("EASY");
		else if(f2) puts("HARD");
		else puts("OKAY");
	
	return 0;

F . NASSA’s Robot

int main() 
	int _ = read;
	while(_--) 
		string s;
		cin >> s;
		int _not = 0,x = 0,y = 0;
		for(int i=0; i<s.size(); i++) 
			if(s[i] == 'U') y ++;
			else if(s[i] == 'D') y --;
			else if(s[i] == 'L') x --;
			else if(s[i] == 'R') x ++;
			else _not ++;
		
		printf("%d %d %d %d\\n",x-_not,y-_not,x+_not,y+_not);
	
	return 0;

G . The Stones Game

int a[107];
int main() 
	int _ = read;
	while(_--) 
		int n = read, m = read, x = read;
		n -= x;
		if(n % m) puts("NO");
		else puts("YES");
	
	return 0;

I . Omar Loves Candies

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int a[1100][1100],sum[1100][1100];
inline int Max(int a, int b)
 return a > b ? a : b; 
int main()
    int _;scanf("%d",&_);
	while(_--)
		int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				scanf("%d",&a[i][j]);
			
		
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				sum[i][j]=a[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
		int ans=-1e9;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				ans=Max(ans,sum[n][m]-sum[n][j-1]-sum[i-1][m]+sum[i-1][j-1]);
				//cout<<i<<" "<<j<<" "<<ans<<endl;
			
		printf("%d\\n",ans);		
	 
    return 0;

J . Modified LCS

#include <bits/stdc++.h>

typedef long long ll;

#pragma region Debug
template<

以上是关于APAC 2013 部分题解 | 训练记录的主要内容,如果未能解决你的问题,请参考以下文章

ECNA 2013 部分题解 | 训练记录

ECNA 2014 部分题解 | 训练记录0703

ECNA 2014 部分题解 | 训练记录0703

2017 google Round C APAC Test 题解

google Round D APAC Test 2017 题解

Codeforces Round #456 (Div. 2) CPerun, Ult!