本文最后更新于 317 天前,其中的信息可能已经有所发展或是发生改变。
题目大意
思想:
代码:
#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; cin >> n;
cout << "Division ";
if(n <= 1399) cout << 4 << endl;
else if(n <= 1599 && n >= 1400) cout << 3 << endl;
else if(n >= 1600 && n <= 1899) cout << 2 << endl;
else cout << 1 << endl;
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想:
map<int,int>
存出现次数。代码:
#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; cin >> n;
int flag = -1;
map<int, int> st;
for(int i = 0; i < n; i ++){
int x; cin >> x;
st[x] ++;
if(st[x] >= 3) flag = x;
}
cout << flag << 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; cin >> n;
int odd1 = 0, even1 = 0;
int odd2 = 0, even2 = 0;
for(int i = 0; i < n; i ++){
int x; cin >> x;
if(i % 2 == 0){
if(x % 2 == 0) even2 ++;
else odd2 ++;
}
else{
if(x % 2 == 0) even1 ++;
else odd1 ++;
}
}
if((odd1 == 0 || even1 == 0) && (odd2 == 0 || even2 == 0)) cout << "YES" << endl;
else cout << "NO" << 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; cin >> n;
string s; cin >> s;
//特判两种情况
if(s.size() == 1){
if(s == "W") cout << "YES" << endl;
else cout << "NO" << endl;
}
else if(s.size() == 2){
if(s == "RB" || s == "WW" || s == "BR") cout << "YES" << endl;
else cout << "NO" << endl;
}
else{
//将 S 以 W 进行分割,判断每个 W 分割的字串
int r = 0, b = 0;
for(int i = 0; i < n; i ++){
if(s[i] == 'W'){ //当遇到 W 则判断截至到上一个 W 的字串的情况
if(r + b < 2){ //小于 2 时
if(r == b && r == 0) continue; //上一个字串不含 RB 跳过
else{
cout << "NO" << endl; //否则无法变成,直接返回
return ;
}
}
else{ //大于 2 时
if(r == 0 || b == 0){ //只含有 R 或者只含有 B 无法满足,直接返回
cout << "NO" << endl;
return ;
}
else r = b = 0; //否则可以满足,此时重置字串状态
}
}
else{ //没遇到 W 更新字串状态
if(s[i] == 'R') r ++;
else b ++;
}
}
if(r + b < 2){ //扫完 S 剩余的最后一个 W 切割的字串
if(r == b && b == 0) cout << "YES" << endl;
else cout << "NO" << endl;
}
else{
if(r == 0 || b == 0) cout << "NO" << endl;
else 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);
bool check(string s1, string s2){
if(s1[0] == s2[0] && s1[1] != s2[1]) return 1;
if(s1[0] != s2[0] && s1[1] == s2[1]) return 1;
return 0;
}
void solve(){
LL sum = 0;
map<string, LL> st;
int n; cin >> n;
for(int i = 0; i < n; i ++){
string s; cin >> s;
st[s] ++;
for(auto &p : st){
if(check(p.fi, s)) sum += p.se;
}
}
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);
LL a[N];
void solve(){
int n; cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
int l = 1, r = n;
LL sum = 0;
LL x = 0, y = 0;
while(l <= r){
if(x == y) sum = l + n - r - 1;
if(x <= y) x += a[l ++];
else y += a[r --];
}
if(x == y) sum = n;
cout << sum << endl;
}
int main(){
IOS;
int _ = 1;
cin >> _;
while(_ --){
solve();
}
return 0;
}