比赛地址:
AtCoder Beginner Contest 297 - AtCoder
A - Double Click
思路 :
直接模拟即可
代码 :
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;inline void solve(){LL n, k ;cin >> n >> k ;vector<int> a(n);for(int& x : a) cin >> x;for(int i=1;i<n;i++){if(a[i]-a[i-1] <= k){cout << a[i] << endl ;return ;}}cout << - 1<<endl;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
B - chess960
思路 :
也是直接模拟即可
代码 :
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;// B K R
int b[2] , r[2] ;bool pd(int x,int y){if(x%2==0 && y%2!=0) return true;if(x%2!=0 && y%2==0) return true;return false;
}inline void solve(){string s ; cin >> s ;int n = s.size() ;s = " " + s;int k = 0;for(int i=1;i<=n;i++){if(s[i]=='B'){if(b[0]!=0) b[1] = i;else b[0] = i;}if(s[i]=='K') k = i;if(s[i]=='R'){if(r[0]!=0) r[1] = i;else r[0] = i;}}if(pd(b[0],b[1]) && k>r[0] && k<r[1]) cout << "Yes" << endl;else cout << "No" << endl; return ;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
C - PC on the Table
思路 :
对于每一行都是从前往后遇到连在一起的T直接变成PC,这样贪心就会得出最大的结果;
代码 :
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int h,w;cin >> h>>w;string s ;while(h--){cin >> s ;for(int i=0;i<w-1;i++){if(s[i]=='T' && s[i+1]=='T') {s[i]='P';s[i+1]='C';i++;}}cout << s << endl;}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
D - Count Subtractions
思路 :
也是直接按照题目意思模拟即可,假设a>b;
此时(cnt表示答案) :
if(a % b == 0){
cnt += a / b - 1 ;
break;
}else{
cnt += a / b ;
a = a % b ;
}
如果遇到a==b直接结束循环,a<b时直接交换a,b;
代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){LL a, b ; cin >> a >> b ;LL cnt = 0 ;while(true){if(a==b){break;}else if(a<b){swap(a, b);}else{if(a % b == 0){cnt += a / b - 1 ;break;}else{cnt += a / b ;a = a % b ;}}}cout << cnt << endl;return ;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
E - Kth Takoyaki Set
思路 :
由于每次都是 和 k个中的一个相加 , 那么直接用set模拟相加的过程即可;
代码 :
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;// 每次都是 和 k个中的一个相加 , 那么直接用set模拟即可 inline void solve(){LL n , k ; cin >> n >> k ;vector<LL> a(n) ;for(int i=0;i<n;i++) cin >> a[i];set<LL> s{0}; // 包含整数 0 ; for(int i=0;i<k;i++){LL x = *s.begin() ;s.erase(x);for(int j=0;j<n;j++){s.insert(x+a[j]);}}cout << *s.begin() << endl;return ;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}