首页 > 其他分享 >11.19膜你赛

11.19膜你赛

时间:2022-11-20 17:24:02浏览次数:71  
标签:11.19 int getchar fa while include define

JYOI 11.19 膜你赛

题目

T1

20pts

枚举全排列即可(也是我这个蒟蒻的考场做法……)

时间复杂度 \(O(kn \times n!)\)

#include <bits/stdc++.h>
#define int long long
#define maxn 105
const int inf = 1e9;
using namespace std;
inline int read(){
    int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; } 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; } 
    return x * f ;
}
int n, k, p;
int tmp[maxn], a[maxn], ans;
bool calc(int x) {
	for (int i = 1; i <= x; i++) {
		int tt[20] = {0};
		for (int j = 1; j <= n; j++) 
			tt[j] = tmp[tmp[j]];
		for (int j = 1; j <= n; j++) tmp[j] = tt[j];
	}
	bool flag = 1;
	for (int i = 1; i <= n; i++) if (tmp[i] != i) flag = 0;
	return flag;
}
signed main() {
	freopen("perm.in", "r", stdin);
	freopen("perm.out", "w", stdout);
	n = read(), k = read(), p = read();
	for (int i = 1; i <= n; i++) a[i] = i;
	do{
		for (int i = 1; i <= n; i++) tmp[i] = a[i];
		if (calc(k)) ans++;
	}while (next_permutation(a + 1, a + n + 1));
	cout << ans % p;
}

40pts

考虑骗 \(k =1\) 的分。

对于 \(k = 1\) 的情况时,这个原序列必须要么是 \(p_i = i\),要么是 \(p_{p_i} = i\),我们可以设计一个 DP:

设 \(f[n]\) 表示长度为 \(n\) 时的方案数。考虑一下怎么转移:首先,若是 \(p_n = n\),那么只将 \(f[n - 1]\)转移过来;还有另一种情况是 \(p_n \ne n\),\(p_n\) 为除了 \(n\) 之外的 \(n - 1\) 种可能,此时,\(n\) 不在本位,那么可以通过观察发现此时的 \(p_n\) 可以决定两个数了,所以对于任何一种情况,方案数都要加 \(f[n - 2]\)。

故状态转移方程为 \(f[n] = f[n - 1] + (n - 1) \times f[n - 2]\)。

60pts

80pts

100pts

++了我都不会呀看了题解也不会

T2

60/80pts

用 \(lcm\) 优化一下,按说只能得60,但是xiaobu的样例出了点问题能得80……

#include <bits/stdc++.h>
#define int long long
#define maxn 1000005
#define inf 1e9
using namespace std;
inline int read(){
    int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; } 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; } 
    return x * f ;
}
int n, m, k, a[maxn], b[maxn];
signed main() {
	freopen("period.in", "r", stdin);
	freopen("preiod.out", "w", stdout);
	n = read(), m = read(), k = read();
	for (int i = 0; i < n; i++) a[i] = read();
	for (int i = 0; i < m; i++) b[i] = read();
	int ans = 0, kans = 0;
	int tmp = __gcd(n, m);
	int kk = tmp * (n / tmp) * (m / tmp);
	if (k < kk) {
		for (int i = 0; i < k; i++) 
			if (a[i % n] < b[i % m]) ans++;
		cout << ans << endl; 
	}
	else {
		for (int i = 0; i < kk; i++) 
			if (a[i % n] < b[i % m]) kans++;
		for (int i = 0; i < k - (k / kk) * kk; i++)
			if (a[i % n] < b[i % m]) ans++;
		ans += (k / kk) * kans;
		cout << ans;
	}
}

100pts

T3

最简单的一道题……然而我手贱,得分还不如暴力……

?~ ?pts

写了个退火……(我个sb

一开始还没读懂题,看见有几个里面选的格式,就想到了退火经典模型,再想到T3应该挺难的正解应该无望,于是开始退火……

RP好像还不怎么行,测试前面几个点也有WA的。

#include <bits/stdc++.h>
#define int long long
#define maxn 1000005
const int inf = 1e9;
using namespace std;
inline int read(){
    int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; } 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; } 
    return x * f ;
}
int n, m, k;
struct edge{
	int u, v, w;
}e[maxn], e2[maxn];
bool cmp(edge a, edge b) {
	return a.w < b.w;
}
vector<int> can, nt;
int Ans, f[maxn], pd[maxn];
int find(register int x) {
	if (f[x] == x) return x;
	return f[x] = find(f[x]);
}
int tot, flag;
int calc() {
	int now = 0;
	for (register int i = 1; i <= n; i++) f[i] = i;
	for (register int i = 0; i < can.size(); i++) {
		int u = e[can[i]].u, v = e[can[i]].v;
		if (find(u) == find(v)) return inf;
		f[find(u)] = find(v);
		now = max(now, e[can[i]].w);
	}
	for (register int i = 1; i <= tot; i++) {
		int u = e2[i].u, v = e2[i].v;
		int x = find(u), y = find(v);
		if (x == y) continue;
		now = max(now, e2[i].w);
		f[x] = y;
	}
	return now;
}
int tt = 0;
vector<int> tmp;
void SA() {
	for (double T = 1000; T > 1e-5; T *= 0.9976) {
		int x = rand() % k, y = rand() % (tt - k);
		swap(can[x], nt[y]);
		int now = calc();
		int del = now - Ans;
		if (del < 0) Ans = now;
		else if (exp(-del / T) * RAND_MAX <= rand()) 
			swap(can[x], nt[y]);
	}
}
signed main() {
	srand(time(0));
	n = read(), m = read(), k = read();
	for (register int i = 1; i <= m; i++) {
		e[i].u = read(), e[i].v = read(), e[i].w = read();
		int opt = read();
		if (!opt) {
			if (tt < k) can.push_back(i);
			else nt.push_back(i);
			tt++;
			pd[i] = 1;
		}
	}
	for (register int i = 1; i <= m; i++) if (!pd[i]) e2[++tot] = e[i];
	sort(e2 + 1, e2 + tot + 1, cmp);
	Ans = calc();
	while ((double)clock() / CLOCKS_PER_SEC < 0.75) SA();
	cout << Ans;
	
}

eee

100pts

二分啊啊啊啊啊啊

既然是最大值最小, 当然是考虑二分。

二分答案之后, 还需要知道用这些边能不能造出一个恰有 \(

标签:11.19,int,getchar,fa,while,include,define
From: https://www.cnblogs.com/Echo-djc/p/16908960.html

相关文章

  • 11.19小记
    上午参加洛谷模拟赛,想了3hT1仍不会正解,想着打个暴力拿80,没想到数组开小只有60,开大之后就100了下午参加端点星,T1一眼,T2写了个nklog,没开O2只有30,T3少看条件认为不可做就溜去......
  • 2022.11.19
    ###noip模拟又炸了。。。。。。##出错点t1:又假了,问题是自己知道假了还没想着写暴力##过程分析半小时通读完先开得t2,因为有个点没转化过来,打了个多一个二分log的......
  • 散乱的思绪-2022.11.19
    我是一个什么都想要,梦想着一步登天的妄想者。我没有一颗聪明绝顶的脑袋,也没有出众样貌,更没有父母的日复一日劳作的毅力。有时候我在想,我是一个什么样的人呢?在我看来我大概......
  • 闲话 22.11.19
    闲话感谢apj先生让我登上了博客园最近闲话阅读量怎么忽高忽低的?一天高一天低了可以说是随便摘了一篇高的11.9怎么是字符串专题啊?这么喜欢看题解为什么不去洛谷给......
  • 11.19.1
    #include<stdio.h>intmain(){ intn,i,j; unsignedlonglongsum=0,ret=1;  scanf("%d",&n); for(i=1;i<=n;i++) {for(j=1;j<=i;j++) {ret*=j; } sum+=ret;ret......
  • flower in 11.19,或者如果您认为的话,一则小的通告
    发布一则公告。三天之内(到11月22日16:00)尽量避免和我的任何线下交流。若非讨论问题一类,大多数交流将被选择性无视。您可能会被瞪一眼,请见谅。到期本条博客将被撤回。当然如......
  • 【流水】2022.11.19
    随便掺点东西罢大家没事也可以打打基本上不熟练的半个小时也就行了ps:看不到的多刷新几遍实在不行粘源码KaTeX入门fixed by 离散小波变换先假设你有一个简单的公式......
  • 11.19考试题解
    记录一下爆炸的模拟赛。T1原题,这道题的题解之前写过,在这。T2由于边数接近点数,整个图的形态接近树,想到建出原图的一个生成树(任意一个),这样两个点的距离分为两类:只经过......
  • 2022.11.19
    2022.11.19搞了搞我的博客园,(之前写是了些什么东西),搞了搞我的电脑。不知道为什么博客园上的背景时有时无的,可惜了我那么好看的图。哦!问题被wxf解决了。想AL了。不......