牛客小白月赛88

超级闪光牛可乐

直接暴力即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// by Totoro
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
const int N = 1e6 + 100;
int main()
{
int x, n;
cin >> x >> n;
int maxn=0;
char y;
rep(i, 1, n)
{
char c;
cin >> c;
ll a;
cin >> a;
if(a>maxn)
{
maxn=a;
y=c;
}
}
if(x/maxn>1000)
{
cout<<-1;
}
else
{
if(x%maxn)
{
x+=maxn;
}
rep(i,1,x/maxn)
{
cout<<y;
}
}
return 0;
}

人列计算机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// by Totoro
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
const int N = 1e6 + 100;
void solve()
{
vector<string> s(5);
for (int i = 0; i < 5; i++)
{
getline(cin, s[i]);
}

char op = s[2][5];
if (op == '&')
{
cout << (int(s[1][0]-'0') & int(s[3][0] - '0'))<< "\n";
}
else if (op == '=')
{
cout << (int(s[1][0]-'0') | int(s[3][0] - '0')) << "\n";
}
else
{
cout << !(s[2][0] - '0') << "\n";
}
}
int main()
{
int t = 1;
while (t--)
{
solve();
}
}

时间管理大师

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// by Totoro
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
const int N = 1e6 + 100;
bool a[N];
int main()
{
int n;
cin>>n;
int ans=0;
rep(i,1,n)
{
int x,y;
cin>>x>>y;
int bell=x*60+y;
int z,b,c;
z=bell-1;
b=bell-3;
c=bell-5;
if(!a[z])
{
ans++;
a[z]=1;
}
if(!a[b])
{
ans++;
a[b]=1;
}
if(!a[c])
{
ans++;
a[c]=1;
}
}
cout<<ans<<'\n';
rep(i,0,24*60)
{
if(a[i])
{
cout<<i/60<<' '<<i%60<<'\n';
}
}


}

我不是大富翁

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// by Totoro
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
const int N = 6000;
bool dp[N][N];
int main()
{
int n,m;
cin>>n>>m;
//dp[i][j]表示第i步能否在J位置
//dp[i][j]=dp[i-1][(j-a[i]+n)%m]|dp[i-1][(j+a[i])%m]
dp[0][0]=1;
rep(i,1,m)
{
int x;
cin>>x;
x%=n;
for(int j=0;j<n;j++)
{
dp[i][j]=dp[i-1][(j+x)%n]|dp[i-1][(j-x+n)%n];
}
}
if(dp[m][0])
{
cout<<"YES"<<'\n';
}
else
{
cout<<"NO"<<'\n';
}


}

多重映射

非常妙,记录了每个数最后变成什么,多体会

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
typedef double db;
#define fi first
#define se second
using i128 = __int128_t;
using piii = pair<ll, pair<ll, ll>>;
const ll inf = 1ll << 60;
const int N = 1e6 + 10;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector<pii> q(m + 1);
map<int, int> t;
for (int i = 1; i <= m; i++)
{
cin >> q[i].fi >> q[i].se;
t[q[i].fi] = q[i].fi;
t[q[i].se] = q[i].se;
}
for (int i = m; i > 0; i--)
{
t[q[i].fi] = t[q[i].se];
}
for (int i = 1; i <= n; i++)
{
if (t.find(a[i]) == t.end())
{
cout << a[i] << ' ';
}
else
{
cout << t[a[i]] << ' ';
}
}
cout << endl;
}

int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}