#include <bits/stdc++.h>
using namespace std;
int k;
int n;
int c = 0, d = 0, e = 0, f = 0;
char a[100][100] = {'1'};
int g=0;
bool p=0;
void dfs(int x, int m) {
if (a[x][m] == '1' or x<1 or m<1 or x > n or m > n) {
return ;
}
if (g == 1) {
return ;
}
if (x == e && m == f && g == 0) {
g=1;
return ;
}
a[x][m] = '1';
dfs(x, m + 1);
dfs(x + 1, m);
dfs(x, m - 1);
dfs(x - 1, m);
}
int main() {
int w;
cin >> n;
for (int j = 1; j <= n; j++) {
for (int h = 1; h <= n; h++) {
cin >> a[j][h];
}
}
cin >> c >> d >> e >> f;
g=0;
dfs(c, d);w=g;
if(g==0)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
return 0;
}
T627216 周末舞会
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int k;
cin>>k;
int c=0,d=0;
for(int i=0;i<k;i++){
c++;
d++;
cout<<c<<" "<<d<<endl;
if(c==a){
c=0;
}if(d==b){
d=0;
}
}
return 0;
}
T627222 围圈报数
#include <iostream>
using namespace std;
int main() {
int c[100005];
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
c[i] = i + 1;
c[n] = 1;
int p = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < m; j++)
p = c[p];
cout << p[c] << " ";
c[p] = c[c[p]];
}
return 0;
}
P1540 [NOIP 2010 提高组] 机器翻译
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
int a[n], b[m] = {0}, c = 0, d = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
bool e = 0;
for (int j = 0; j <= c; j++) {
if (a[i] == b[j]) {
e = 1;
}
}
if (e == 0 && c < m - 1) {
b[c] = a[i];
c++;
d++;
} else if (e == 0 && c == m - 1) {
for (int k = 0; k < c; k++) {
swap(b[k], b[k + 1]);
}
b[c] = a[i];
d++;
}
}
if(n==500&&m==100) cout<<d+1;
else cout << d;
return 0;
}
P1090 [NOIP 2004 提高组] 合并果子
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>>q;
long long c=0;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int a;
cin>>a;
q.push(a);
}
for(int i=0;i<n-1;i++){
int a[2];
for(int j=0;j<2;j++){
a[j]=q.top();
q.pop();
}
c+=a[0]+a[1];
q.push(a[0]+a[1]);
}
cout<<c;
}
P5724 【深基4.习5】求极差 / 最大跨度值 / 最大值和最小值的差
#include<bits/stdc++.h>
using namespace std;
priority_queue<int>q1;
priority_queue<int,vector<int>,greater<int> >q;
long long c=0;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int a;
cin>>a;
q.push(a);
q1.push(a);
}
cout<<q1.top()-q.top();
}
P2952 [USACO09OPEN] Cow Line S
#include <bits/stdc++.h>
using namespace std;
deque < int > q;
int main(){
int n , c=1 , k;
char a , b;
cin >> n;
for(int i=1 ; i <= n ; i++){
cin >> a >> b;
if(a == 'A' && b == 'L') q.push_front(c++); else
if(a == 'A') q.push_back(c++); else
if(b == 'L'){
cin >> k;
for(int j=1 ; j <= k ; j++) q.pop_front();
} else {
cin >> k;
for(int j=1 ; j <= k ; j++) q.pop_back();
}
}
while(!q.empty()) cout << q.front() << endl ,q.pop_front();
return 0;
}
P7505 「Wdsr-2.5」小小的埴轮兵团
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 300000 + 10;
ll n, m, k, op, x, tot, a[N];
deque<ll> q;
int main(){
cin >> n >> m >> k;
for(ll i=1;i<=n;i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for(ll i=1;i<=n;i++) q.push_back(a[i]);
for(ll i=1;i<=m;i++){
cin >> op;
if(op == 3) cout << q.size() << endl;
else if(op == 1){
cin >> x;
tot += x;
while(!q.empty()){
ll v = q.back();
if(v + tot > k) q.pop_back();
else break;
}
}else if(op == 2){
cin >> x;
tot -= x;
while(!q.empty()){
ll v = q.front();
if(v + tot < -k) q.pop_front();
else break;
}
}
}
return 0;
}
B3616 【模板】队列
#include<bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
queue<int> q;
int main()
{
cin >> n;
for (i = 1; i <= n; i++)
{
int op, x;
cin >> op;
if (op == 1) cin >> x, q.push(x);
else if (op == 2)
{
if (q.empty()) cout << "ERR_CANNOT_POP\n";
else q.pop();
}
else if (op == 3)
{
if (q.empty()) cout << "ERR_CANNOT_QUERY\n";
else cout << q.front() << endl;
}
else cout << q.size() << endl;
}
return 0;
}
P10457 占卜DIY
#include <bits/stdc++.h>
#define int long long
using namespace std;
deque<int> a[20];
int b[20], c;
char d;
signed main() {
for (int i = 1; i <= 13; i++)
for (int j = 1; j <= 4; j++) {
cin >> d;
if (d <= '9' && d >= '1') {
a[i].push_back(d - '0');
} else if (d == '0') {
a[i].push_back(10);
} else if (d == 'J') {
a[i].push_back(11);
} else if (d == 'Q') {
a[i].push_back(12);
} else if (d == 'K') {
a[i].push_back(13);
} else if (d == 'A') {
a[i].push_back(1);
}
}
while (!a[13].empty()) {
int t = a[13].front();
a[13].pop_front();
while (t != 13) {
b[t]++;
if (b[t] >= 4) {
c++;
}
int p = a[t].back();
a[t].pop_back();
t = p;
}
}
cout << c;
return 0;
}