2018-2019 Asia Nanjing Regional Contest

A - Adrien and Austin Gym - 101981A

博弈思维题,一开始没想明白,最后才整明白,真的很简单

思维:
  • 其实也就是3种情况吧,一种是 n = = 0 n == 0 n==0 的情况,这种后手肯定赢
  • 第二种是n 为偶数, k 为 1 这样后手也肯定赢
  • 第三种是就是剩余的情况,因为剩余情况总能变成两堆相同的,根据前面的来走后面的即可(第二种情况不可)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>
#include <cmath>
#include <deque>

using namespace std;

typedef long long ll;

const int N = 100010, M = 200010;
const int mod = 1e9 + 7;

int main(){
    int n, k;
    scanf("%d%d",&n,&k);
    if (!n || (n % 2 == 0 && k == 1)) puts("Austin");
    else puts("Adrien");
    return 0;
}


Problem E. Eva and Euro coins

也是思维题吧,很巧妙,运用了栈(数组模拟也可,不过稍微麻烦一点),首先要理解题意很重要

思想:
  • 先大体说下题意吧,给两个长度为n的字符串,可以翻转连续k个相同的字符,最后问是否可以让两个字符串相同
  • 做题的时候读错了,然后就一直wa,看了看网上的题解,也是很巧妙的
  • 首先我们可以想,我们可以直接删除k个连续相同的字符,只要连续k个就直接删除就行,因为他都可以转换为同一位置,比如100010 和 110000,我们就转换第一个字符串,先转换成111110 - > 110000,大体意思就是我们可以根据反转,来慢慢移动位置(这个可以自己举几个例子,写一下就明白了)
  • 所以我们删除相同k个元素,然后将剩下的连接到一起,我们判断他最终是否相同即可
  • 删除与连接都运用了2个栈,记录个数和对应的字符,看代码就明白了
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>
#include <cmath>
#include <deque>

using namespace std;

typedef long long ll;

const int N = 100010, M = 200010;
const int mod = 1e9 + 7;

int st1[N], st2[N];
int cnt1, cnt2;

int n, k;

string solve(string s){
	stack<char> st;
	stack<int> num;
	for (int i = 0 ; i < n; i++){
		if (st.empty() || st.top() != s[i]){
			st.push(s[i]);
			num.push(1);
		}
		else{
			if (num.top() +  1 == k){
				st.pop();
				num.pop();
			}
			else{
				int m = num.top();
				num.pop();
				num.push(m + 1);
			}
		}
	}
	string str = "";
	while(!st.empty()){
		char t = st.top();
		st.pop();
		int m = num.top();
		num.pop();
		for (int i = 1; i <= m; i ++){
			str += t;
		}
	}
	return str;
}

int main(){
    scanf("%d%d",&n,&k);
    string s1, s2;
    cin>>s1>>s2;
    if (k == 1){
    	puts("Yes");
    	return 0;
    }
    if (solve(s1) == solve(s2)){
    	puts("Yes");
    }
    else{
    	puts("No");
    }
    // puts("Yes");
    return 0;
}


G - Pyramid Gym - 101981G

G题数学题,主要是推出公式,做的时候是瞎蒙的,公式很奇妙,学的很多新方法

思想:
  • 首先我们可以得出 n 层可以构成三角形的个数,我们可以举例: 1 − 5 − 15 − 35 − 70 − 126 1 - 5 - 15 - 35 - 70 -126 15153570126, 他们的第一次做差为 4 10 20 35 56,第二次为6 10 15 21, 第三次为 4 5 6,第四次为1 1 1,为4次方程
  • 所以方程式子可以表示为 f ( x ) = a x 4 + b x 3 + d x 2 + k x + c f(x) = ax^4 + bx^3+dx^2+kx + c f(x)=ax4+bx3+dx2+kx+c, 然后把数值带入,即可求出方程
  • 方程最后为 f ( x ) = n ∗ ( n + 1 ) ∗ ( n + 2 ) ∗ ( n + 3 ) / 24 f(x) = n * (n +1) * (n + 2) * (n + 3) / 24 f(x)=n(n+1)(n+2)(n+3)/24 ,最后利用逆元求解即可
  • 举例可以利用打表的方法,数组存每个点的坐标然后打表
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>
#include <cmath>
#include <deque>

using namespace std;

typedef long long ll;

const int N = 100010, M = 200010;
const int mod = 1e9 + 7;

ll mod_exp(ll a,ll b,ll m){
    ll res = 1;
    ll exp = a % m;
    while(b){
        if (b & 1) res = res * exp % m;
        exp = exp * exp % m;
        b>>=1;
    }
    return res;
}

int main(){
    int t;
    scanf("%d",&t);
    ll y = mod_exp(24,mod - 2,mod); 
    while(t--){
    	ll n;
    	scanf("%lld",&n);
    	ll res = n * (n + 1) % mod * (n + 2) % mod *(n + 3)% mod * y % mod;
    	
    	printf("%lld\n",res);
    }
    return 0;
}


I - Magic Potion Gym - 101981I

I题用两次匈牙利模板即可,也没啥好说的,不过还有网络流的写法,到时候学习一下

思想:
  • 首先是匈牙利最大匹配一波,然后根据剩下的,再匹配一波,跟药水取最小值即可
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N =510, M =100010;

int ne[M], e[M], h[N];

bool st[N];
int idx;
int match[N];

void add(int x, int y){
    e[idx] = y, ne[idx] = h[x], h[x] = idx++;
}

bool Find(int x){
    for (int i = h[x]; i != -1; i = ne[i]){
        int j = e[i];
        if (!st[j] ){
            st[j] = true;
            if (match[j] == 0 || Find(match[j])) {
                match[j] = x;
                return true;
            }
        }
    }
    return false;
}

int main(){
    int n1, n2, m;
    scanf("%d%d%d",&n1,&n2,&m);
    memset(h,-1,sizeof h);
    for(int i = 1; i <= n1; i ++){
    	int x;
    	scanf("%d",&x);
    	for (int j =1; j <= x; j ++){
    		int y;
    		scanf("%d",&y);
    		add(i,y);
    	}
    }
    int res = 0;
    for (int i = 1; i <= n1; i++){
        memset(st,false,sizeof st);
        if (Find(i)) res ++;
    }
    int res1 = 0;
    for (int i = 1; i <= n1; i ++){
    	memset(st,false,sizeof st);
    	if (Find(i)) res1 ++;
    }
    printf("%d\n",res + min(res1, m));
    return 0;
}


J - Prime Game Gym - 101981J

数学思维题吧,感觉还是读懂题意比较重要!

思想:
  • 先说下这个题的题目意思吧,求 a 1 , a 1 ∗ a 2 , a 1 ∗ a 2 ∗ a 3 , . . . . , a 1 ∗ a 2 ∗ a 3.. a n − 1 ∗ a n a1, a1 * a2, a1 *a2*a3,.... ,a1 * a2 * a3..an-1*an a1,a1a2,a1a2a3,....,a1a2a3..an1an a 2 , a 2 ∗ a 3... a2,a2*a3... a2,a2a3... 大体这个意思,一会再举个例子,然后求他们不同的质因子的数目

在这里插入图片描述

  • 首先我们可以发现a1 会影响 n 个数,a2 影响 2 * (n - 1),a3影响 3 * (n - 2),依次类推
  • 首先我们看a1,可以影响n个数,当我们求到a2影响时,如果发现a1已经影响了,那么我们减去他的层数,这样我们就可以不影响前面已经影响的层数,这个层数需要记录下(看代码应该可以理解)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <stack>
#include <cmath>
#include <deque>

using namespace std;

typedef long long ll;

const int N = 1000010, M = 2000010;
const int mod = 1e9 + 7;

ll a[N];
ll b[N];

int main(){
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= n; i ++){
    	scanf("%lld",&a[i]);
    }
    ll res = 0;
    for (int i = 1; i <= n ; i++){
    	ll x = a[i];
    	for (int j = 2; j *j <= x; j ++){
    		while (x % j == 0){
    			res += (n - i + 1) * (i - b[j]) ;
    			b[j] = i;
    			x /= j;
    		}
    	}
    	if (x > 1){
    		res += (n - i + 1) * (i - b[x]) ;
    		b[x] = i;
    	}
    }
    printf("%lld\n",res);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值