手速场 …
文章目录
一、A - Burenka Plays with Fractions
- 题目: 给你a / b,c / d 每次分子或者分母都可以乘一个数字,问最少几次可以让 a / b = c / d;
- 思路:
这个交叉相乘就是 a * d = b * c,然后判断即可
-代码:
#include <bits/stdc++.h>
#define int long long
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int>
#define endl '\n'
using namespace std;
const int N = 2e5 + 100,M = 4e5 + 100,INF = 0x3f3f3f3f,mod = 1e7 + 7;
void solve()
{
int a,b,c,d; cin >> a >> b >> c >> d;
int k = a * d;
int w = b * c;
// cout << k << ' ' << w << endl;
if(k == w) cout << "0" << endl;
else if(a == 0 || c == 0) cout << "1" << endl;
else if(k % w == 0 || w % k == 0) cout << "1" << endl;
else cout << "2" << endl;
}
signed main()
{
ios;
int T; cin >> T;
while(T -- )
solve();
return 0;
}
二、B - Interesting Sum
- 题目:
你选择一个[L,R],让 max(a[1],a[2]…a[L - 1],a[R + 1)…a[n]) - min(a[1],a[2]…a[L- 1],a[R + 1)…a[n]) + max(a[L] + a[L + 1] + …A[R]) - min(a[L] + a[L + 1] + …A[R]) 最大 - 思路:
- 这个不管如何取总是能取到最大值和次大值和最小次和次小值,那就直接sort就行
- 代码:
#include <bits/stdc++.h>
#define int long long
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int>
#define endl '\n'
using namespace std;
const int N = 2e5 + 100,M = 4e5 + 100,INF = 0x3f3f3f3f,mod = 1e7 + 7;
int a[N];
void solve()
{
int n; cin >> n;
for(int i = 1;i <= n;i ++ ) cin >> a[i];
sort(a + 1,a + 1 + n);
cout << a[n] + a[n - 1] - a[1] - a[2] << endl;
}
signed main()
{
ios;
int T; cin >> T;
while(T -- )
solve();
return 0;
}
三、C - Corners
- 题目:
给了n行m列的表格,只由0和1组成,每次你可以选择一个 L 形状的图形,也就是选择3个格子,这3个格子得是连在一起形状是L形状的,这3个格子里面的1必须变成0,问你最多几次能够把表格中的1变成0? - 思路:
只要你某一个含0最多的正方形的网格(4个格子),里面有不小于两个0,那答案就是1的个数,否则如果有1个0那就是有3个1,第一次L就会消除两个1,其余每次都消除一个1,答案就是 1的个数 - 1,如果0的个数是 0,那就是第一次会消除3个1,其余每次都消除一个1,答案就是1的个数 - 2 - 代码:
#include <bits/stdc++.h>
#define int long long
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int>
#define endl '\n'
using namespace std;
const int N = 2e5 + 100,M = 4e5 + 100,INF = 0x3f3f3f3f,mod = 1e7 + 7;
char a[510][510];
void solve()
{
int n,m; cin >> n >> m;
int d = 0;
for(int i = 1;i <= n;i ++ )
for(int j = 1;j <= m;j ++ )
{
cin >> a[i][j];
if(a[i][j] == '1')
d++;
}
int mx = -1;
for(int i = 1;i <= n - 1;i ++ )
{
for(int j = 1;j <= m - 1;j ++ )
{
int cnt = 0;
if(a[i][j] == '0') cnt++;
if(a[i][j + 1] == '0') cnt++;
if(a[i + 1][j] == '0')cnt++;
if(a[i + 1][j + 1] == '0')cnt++;
mx = max(mx,cnt);
}
}
if(mx >= 2) cout << d << endl;
else if(mx == 1) cout << max((int)0,d - 1) << endl;
else cout << max((int)0,d - 2) << endl;
}
signed main()
{
ios;
int T; cin >> T;
while(T -- )
solve();
return 0;
}
四、D1 - Xor-Subsequence (easy version)
- 题目:
这个题目就是难懂了一点,但是还是挺简单的,B这个数组中的元素就是A的下标, 不描述了,博主口齿不伶俐,表达不出来 - 思路:
因为a[i] <= 200,是一个7位的二进制 所以每一个 a[i]最多往前枚举256,就行 ,枚举情况暴力dp,就是求最长上升子序列的dp,dp[i],是以i为结尾的满足条件的最长子序列 - 代码:
#include <bits/stdc++.h>
#define int long long
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define PII pair<int,int>
#define endl '\n'
using namespace std;
const int N = 3e5 + 100,M = 4e5 + 100,INF = 0x3f3f3f3f,mod = 1e7 + 7;
int a[N],cnt[N];
int f[N];
int n,m;
void solve()
{
cin >> n;
int ans = -1;
for(int i = 0;i < n;i ++ ) cin >> a[i];
for(int i = 0;i <= n;i ++ )
{
f[i] = 1;
for(int j = max((int)0,i - 256);j < i ;j ++ )
{
if((a[j] ^ i) < (a[i] ^ j))
{
f[i] = max(f[i],f[j] + 1);
}
}
}
for(int i = 0;i < n;i ++ ) ans = max(ans,f[i]);
cout << ans<< endl;
}
signed main()
{
ios;
int T; cin >> T;
while(T -- )
solve();
return 0;
}