Daliy Algorithm (模拟,哈希)-- day 66
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.25
每次都有五个监督我打卡的小伙伴你们都是谁呢 😇
今天是一个吉利的数字呢!!!
Exercising Walk
考察: 数学 , 思维
思路:
首秀按我们按照最小得移动策略 即 左右两边至少移动 (b - a) 上下至少移动 (d - c) 次
我们得出了移动需求后只需要判断加上原坐标得基础上是否满足要求即可
但是需要注意得是要特判 x1 == x2 和 y1 == y2 得情况且步数大于0得情况
#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;
int t;
void slove()
{
int a , b , c , d;
int x, y , x1 , x2 , y1, y2;
cin >> a >> b >> c >> d;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
ll tx = x + (b - a);
ll ty = y + (d - c);
if(x1 == x2 && (a > 0 || b > 0))
{
cout << "NO" << endl;
return;
}
if(y1 == y2 && (c > 0 || d > 0))
{
cout << "NO" << endl;
return;
}
if(tx >= x1 && tx <= x2 && ty >= y1 && ty <= y2)
cout << "YES" << endl;
else cout << "NO" << endl;
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}
Dreamoon and Ranking Collection
哈希 映射
#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;
int t;
void slove()
{
int n , x;
cin >> n >> x;
vector<int> a(n);
vector<bool> vis(200,false);
for(int i = 0;i < n ;i ++)
{
cin >> a[i];
vis[a[i]] = true;
}
int ans = 0 , i = 1;
while(x > 0 || vis[i])
{
if(vis[i]){
i++ ;ans++;
}
else if(x > 0){
vis[i++] = 1;
x--;
ans++;
}else {
break;
}
}
cout << ans << endl;
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}
王子公主配对 23333
模拟,哈希
#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;
const int N = 100005;
typedef long long ll;
const int MAX = 0x7ffffff;
int t;
void slove()
{
int n;
cin >> n;
vector<int> a(n + 1);
vector<int> princess(n + 1,0), princes(n + 1,0);
int cnt = 0 , k;
for(int i = 1;i <= n ;i ++)
{
cin >> k;
for(int j = 1;j <= k ;j ++)cin >> a[j];
for(int j = 1;j <= k; j ++)
{
if(princes[a[j]] == 0)
{
princes[a[j]] = 1;
princess[i] = 1;
cnt++;
break;
}
}
}
if(cnt == n)
{
cout << "OPTIMAL" << endl;
}else{
int a = n,b = n;
for(int i = 1;i <= n ;i ++)
{
if(princess[i] == 0)
{
a = min(a , i);
}
if(princes[i] == 0)
{
b = min(b , i);
}
}
cout << "IMPROVE" << endl;
cout << a << " " << b << endl;
}
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}

浙公网安备 33010602011771号