Daliy Algorithm (数学,小知识)-- day 67
Nothing to fear
those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out
那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~
2020.4.27
拉姆塞定理
拉姆塞定理
拉姆塞理论可以用通常的语言来表述。
在一个集会上,两个人或者彼此认识,或者彼此不认识,
拉姆塞得出结果是说,当集会人数大于或等于6时,
则必定有3个人,他们或者彼此认识或者彼此都不认识。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int N = 1005;
const int MAX = 0x7ffffff;
int t;
int edge[N][N];
void slove()
{
int n , m;
cin >>n >> m;
int a , b;
// 根据拉塞姆定理 当 n >= 6时一定有一方三条边可以构成三角形
if(n >= 6)
{
for(int i = 0; i< m ;i ++)cin >> a >> b;
printf("yes\n");
return;
}
memset(edge , 0 , sizeof edge);
for(int i = 1;i <= m ;i ++)
{
cin >> a >> b;
edge[a][b] = edge[b][a] = 1;
}
int flag = 0;
for(int i = 1;i <= n ;i ++)
{
for(int j = i + 1;j <= n && !flag ;j ++)
{
for (int k = j + 1; k <= n && !flag; k++)
if (edge[i][j] == edge[j][k] && edge[j][k] == edge[k][i])
flag = 1;
}
}
if (flag) printf("yes\n");
else printf("no\n");
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}
牛妹的游戏
这个题需要先打表观察出来符合的组合数的规律在进行计算
数学观察题 这种题要多做才能有感觉啊!
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
const int mod = 998244353;
int t;
const int N = 5005;
ll a[N][N];
// 初始化组合数
void initComb()
{
for(int i = 0;i <= N ;i ++)
{
a[i][0] = 1;
}
for(int i = 1;i < N ;i ++)
{
for(int j = 1;j < N ;j ++)
{
a[i][j] = (a[i-1][j] + a[i-1][j-1]) % mod;
}
}
}
void slove()
{
int x , y , time;
cin >> x >> y >> time;
if(time < x || time - x < y)
{
cout << 0 << endl;
}else cout << a[time][x] % mod * a[time-x][y] % mod << endl;
return ;
}
int main()
{
SIS;
initComb();
cin >> t;
while(t--)
{
slove();
}
}