本文最后更新于 321 天前,其中的信息可能已经有所发展或是发生改变。
题目大意
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
int a[N];
void solve(){
int vis[1010] = {0};
int n; cin >>n;
for(int i = 0; i < n; i ++) cin >> a[i];
string s; cin >> s;
for(int i = 0; i < s.size(); i ++){
if(vis[a[i]] == 0){
vis[a[i]] = s[i];
}
else{
if(vis[a[i]] != s[i]){
cout << "NO" << endl;
return ;
}
}
}
cout << "YES" << endl;
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
void solve(){
LL sum = 0;
LL odd = 0, even = 0;
int n, q; cin >> n >> q;
for(int i = 0; i < n; i ++){
LL x; cin >> x;
if(x % 2 == 0) even ++;
else odd ++;
sum += x;
}
while(q --){
int op, k; cin >> op >> k;
if(op == 0){
if(k % 2 == 0) um += even * k;
else{
sum += even * k;
odd += even; even = 0;
}
}
else{
if(k % 2 == 0) sum += odd * k;
else{
sum += odd * k;
even += odd; odd = 0;
}
}
cout << sum << endl;
}
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
void solve(){
int n;
string op;
cin >> n >> op;
string s; cin >> s;
int t = s.size();
s = s + s;
int pos = s.find(op);
int res = -1;
for(int i = 0; i < t + pos + 1; i ++){
int cnt = 0;
if(s[i] == op[0]){
while(s[i] != 'g' && i < s.size()){
cnt ++; i ++;
}
res = max(res, cnt);
}
}
cout << res << endl;
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
int f(LL n){
int cnt = 0;
while(n % 2 == 0){
n /= 2;
cnt ++;
}
return cnt ;
}
void solve(){
LL sum = 0;
priority_queue<int> st;
int n; cin >> n;
for(int i = 1; i <= n; i ++){
LL x; cin >> x;
sum += f(x);
st.push(f(i));
}
int cnt = 0;
while(!st.empty() && sum < n){
sum += st.top(); st.pop();
cnt ++;
}
if(sum >= n) cout << cnt << endl;
else cout << -1 << endl;
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}