标签:vector struct 比赛 pre queue round nod als eof
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int t,x,y,n;
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>x>>y>>n;
int tmp=n/x;
if(tmp*x+y>n){
tmp--;
}
tmp=tmp*x+y;
cout<<tmp<<"\n";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int t,n;
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
if(n==1){
cout<<"0"<<"\n";
continue;
}
int ans=0;
int f=0;
while(n!=1){
if(n%6==0){
n/=6;
ans++;
}else{
if(n%3==0){
n*=2;
ans++;
}else{
cout<<"-1"<<"\n";
f=1;
break;
}
}
}
if(!f){
cout<<ans<<"\n";
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int t,n;
string s;
queue<char>q;
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
cin>>s;
int tmp=0;
for(int i=0;i<s.size();++i){
if(s[i]==‘(‘){
q.push(s[i]);
}
if(s[i]==‘)‘){
if(q.size()!=0){
q.pop();
}else{
tmp++;
}
}
}
cout<<tmp<<"\n";
while(!q.empty()) q.pop();
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
ll t, n, k, a[maxn];
int main()
{
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n >> k;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] %= k;
}
sort(a + 1, a + 1 + n);
ll r = 0;
for (int i = 1; i <= n; ++i) if (!a[i]) r++;
if (r == n) {
cout << "0" << "\n";
continue;
}
ll ans = 0;
ll tmp = 0;
a[n + 1] = 888;
for (int i = 1; i <= n ; ++i) {
if (a[i]) {
if (a[i] == a[i - 1]) {
ans = max(ans, (a[i] / k + 2 + tmp) * k - a[i]);
tmp++;
}
else {
tmp = 0;
ans = max(ans, (a[i] / k + 1 + tmp) * k - a[i]);
}
}
}
cout << ans + 1 << "\n";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int maxn = 2e5 + 10;
int n, k;
struct node {
int t, a, b;
//node(int a1,int a2,int a3){t=a1,a=a2,b=a3;}
};
vector<node>rec[3];
bool cmp(node a, node b)
{
return a.t > b.t;
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
int a, b, c;
cin >> a >> b >> c;
node w;
w.t = a, w.a = b, w.b = c;
if (b == 1 && c == 1) rec[0].push_back(w);
else {
if (b == 1) rec[1].push_back(w);
if (c == 1) rec[2].push_back(w);
}
}
sort(rec[0].begin(), rec[0].end(), cmp);
sort(rec[1].begin(), rec[1].end(), cmp);
sort(rec[2].begin(), rec[2].end(), cmp);
if (rec[0].size() + min(rec[1].size() , rec[2].size() ) < k) {
cout << "-1";
return 0;
}
int res = 0, ans = 0;
while (res < k) {
node a1, a2, a3;
if (rec[0].size() != 0) a1 = rec[0].back();
if(rec[1].size()!=0) a2 = rec[1].back();
if (rec[2].size() != 0) a3 = rec[2].back();
if (rec[0].size() == 0) {
rec[1].pop_back();
rec[2].pop_back();
res++;
ans += (a2.t + a3.t);
continue;
}
if (rec[1].size() == 0 || rec[2].size() == 0 ||a1.t < a2.t + a3.t) {
rec[0].pop_back();
res++;
ans += a1.t;
}
else {
rec[1].pop_back();
rec[2].pop_back();
res++;
ans += (a2.t + a3.t);
}
}
cout << ans;
return 0;
}
Codeforces Round #653 (Div. 3)题解
标签:vector struct 比赛 pre queue round nod als eof
原文地址:https://www.cnblogs.com/DrumWashingMachine-Lhy-NoobInCsu/p/13208778.html