--- 題型 ---
放剩下 相關的題目 ψ(._. )>
/*
* CSES
* Distinct Numbers
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int n;
cin >> n;
set<int>arr;
for(int i=0;i<n;++i){
int x;
cin >> x;
arr.insert(x);
}
cout << arr.size() << endl;
}
/*
* zerojudge
* b304. 00673 - Parentheses Balance
*/
#include<bits/stdc++.h>
using namespace std;
bool isOk(char open, char close) {
if(open == '(' && close == ')'){
return 1;
}else if(open == '[' && close == ']'){
return 1;
}else if(open == '{' && close == '}'){
return 1;
}else{
return 0;
}
}
bool isCheck(char c){
if(c=='('){
return 1;
}else if(c==')'){
return 1;
}else if(c=='['){
return 1;
}else if(c==']'){
return 1;
}else if(c=='{'){
return 1;
}else if(c=='}'){
return 1;
}else{
return 0;
}
}
int main(){
int n;
cin >> n;
cin.ignore();
while(n--){
stack<char>st;
string s;
getline(cin,s);
for(int i=0;i<s.size();++i){
if( !st.empty() && isOk(st.top(),s[i])){
st.pop();
}else if(isCheck(s[i])){
st.push(s[i]);
}
}
cout << ( (st.empty()==1) ? "Yes" : "No" ) << endl;
}
}
/*
* ASOJ
* 池塘 (Pond)
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, w, q;
cin >> n >> m >> k >> w >> q;
vector<vector<bool>> Pond_relation(n, vector<bool>(n, false));
vector<vector<int>> Pond_fish(n, vector<int>(k, 0));
vector<int> Pond_weight(n, 0);
// ------------------------------------------------
for (int ni = 0; ni < n; ++ni) {
for (int mi = 0; mi < m; ++mi) {
int temp;
cin >> temp;
Pond_relation[ni][temp - 1] = true;
}
}
for (int ni = 0; ni < n; ++ni) {
for (int ki = 0; ki < k; ++ki) {
int temp;
cin >> temp;
Pond_fish[ni][ki] = temp;
Pond_weight[ni] += temp;
}
}
for (int qi = 0; qi < q; ++qi) {
int aloc, afish, bloc, bfish;
cin >> aloc >> afish >> bloc >> bfish;
aloc -= 1;
bloc -= 1;
// ------------------------------------------------
bool isOk[2] = {false, false};
int ai=0,bi=0;
if (Pond_relation[aloc][bloc]==true){
for (ai = 0; ai < k; ++ai) {
if (Pond_fish[aloc][ai] == afish) {
Pond_weight[aloc] -= afish;
Pond_weight[bloc] += afish;
isOk[0] = true;
break;
}
}
for (bi = 0; bi < k; ++bi) {
if (Pond_fish[bloc][bi] == bfish) {
Pond_weight[bloc] -= bfish;
Pond_weight[aloc] += bfish;
isOk[1] = true;
break;
}
}
}
// ------------------------------------------------
if (isOk[0]==true && isOk[1]==true) {
cout << "YES";
int temp = Pond_fish[aloc][ai];
Pond_fish[aloc][ai]=Pond_fish[bloc][bi];
Pond_fish[bloc][bi]=temp;
} else {
cout << "NO";
}
// ------------------------------------------------
int sum = 0;
for (int ni = 0; ni < n; ++ni) {
if (Pond_weight[ni] > w) {
sum += k;
}
}
cout << " " << sum << endl;
}
return 0;
}
/*
Sprout OJ
No. 19
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;cin >> t;
while(t--){
int n;cin >> n;
vector<int>b;
b.resize(n);
stack<int>a;
stack<int>temp;
//
for(int i=n;i>=1;--i){
a.push(i);
}
for(int i=0;i<n;++i){
cin >> b[i];
}
//
int check = 0;
for(int i=0;i<n;++i){
while( !a.empty() ){
if(!temp.empty()){
if(temp.top() == b[check]){
break;
}
}
temp.push(a.top());
a.pop();
}
while(!temp.empty()){
if(temp.top()==b[check]){
temp.pop();
check+=1;
}else{
break;
}
}
}
if(check==n){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
Last updated
Was this helpful?