比赛链接:https://codeforces.com/gym/105544
这次是赛时8题
A.Counterfeit Money
#include<bits/stdc++.h>
#define endl '\n'using namespace std;
typedef long long ll;const int INF=0x3f3f3f3f;
const int N=2e5+5;ll t,n,m;void fio(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}void solve(){string str;cin >> str;n=str.length();ll ttt=(3-n%3)%3;for(int i=1; i<=ttt; i++){str='0'+str;}n=str.length();//cout << str << endl;ll op=1;ll ans=0;for(int i=n-3; i>=0; i-=3){string tmp=str.substr(i,3);//cout << tmp << endl;ll tt=0;for(auto j:tmp){tt*=10;tt+=j-'0';}if(op){ans+=tt;op^=1;}else{ans-=tt;op^=1;}}ans=llabs(ans);cout << ans << " ";if(ans%13==0){cout << "YES" << endl;}else cout << "NO" << endl;}signed main()
{fio();cin >> t;//t=1;while(t--){solve();}return 0;
}
B.Recurring Decimal to Fractions
#include<bits/stdc++.h>
#define endl '\n'using namespace std;
typedef long long ll;const int INF=0x3f3f3f3f;
const int N=2e5+5;ll t,n,m;ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x;}x = x*x;y >>= 1;}return ans;
}ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}void fio(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}void solve(){ll a,b;ll num1,num2;cin >> a >> b >> num1 >> num2;ll fenzi=num2, fenmu=(ksm(10,b)-1)*ksm(10,a);ll tmp=gcd(fenmu,fenzi);fenmu/=tmp,fenzi/=tmp;//cout << fenzi << " " << fenmu << endl;fenzi=fenzi*ksm(10,a)+fenmu*num1;fenmu*=ksm(10,a);tmp=gcd(fenzi,fenmu);fenmu/=tmp,fenzi/=tmp;cout << fenzi << " " << fenmu << endl;
}signed main()
{fio();cin >> t;//t=1;while(t--){solve();}return 0;
}
C.Where the Lantern Lights are Dimming
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct tree
{ll l, r, o, ot, v, vt;ll gs;ll ys;ll sum;
}p[1000005 << 2];
vector<pair<ll, ll>>a(1000005);//0~n-1
void push_up(ll i)
{p[i].v = p[i << 1].v + p[i << 1 | 1].v;p[i].sum = p[i << 1].sum + p[i << 1 | 1].sum;p[i].gs = p[i << 1].gs + p[i << 1 | 1].gs;p[i].ys= p[i << 1].ys + p[i << 1 | 1].ys;return;
}
void build(ll i, ll l, ll r)
{p[i].l = l, p[i].r = r;if (l == r){p[i].o = a[l].first;p[i].ys=0;p[i].gs = 0;p[i].ot = 0;if (p[i].o==1)p[i].v = a[l].second, p[i].gs = 1;else if(p[i].o==-1)p[i].ys=1;p[i].sum = a[l].second;return;}build(i << 1, l, l + r >> 1);build(i << 1 | 1, (l + r >> 1) + 1, r);push_up(i);return;
};
void push_down(ll i)
{if (p[i].ot){p[i << 1].v = p[i << 1].sum - p[i << 1].v;p[i << 1 | 1].v = p[i << 1 | 1].sum - p[i << 1 | 1].v;p[i << 1].gs = p[i << 1].r - p[i << 1].l + 1 -p[i<<1].ys- p[i << 1].gs;p[i << 1 | 1].gs = (p[i << 1 | 1].r - p[i << 1 | 1].l + 1)-p[i<<1|1].ys - p[i << 1 | 1].gs;p[i << 1].ot ^= 1;p[i << 1 | 1].ot ^= 1;p[i].ot = 0;}return;
}
void u1(ll i, ll l, ll r)//异或
{if (p[i].l == l && p[i].r == r){p[i].ot ^= 1;p[i].gs = p[i].r - p[i].l + 1-p[i].ys - p[i].gs;//个数p[i].v = p[i].sum - p[i].v;return;}push_down(i);ll mid = (p[i].l + p[i].r) >> 1;if (l <= mid)u1(i << 1, l, min(r, mid));if (r >= mid + 1)u1(i << 1 | 1, max(l, mid + 1), r);push_up(i);
}
ll q(ll i, ll l, ll r)
{ll ans = 0;if (p[i].l == l && p[i].r == r){ans += p[i].sum;return ans;}push_down(i);ll mid = (p[i].l + p[i].r) >> 1;if (l <= mid)ans += q(i << 1, l, min(r, mid));if (r >= mid + 1)ans += q(i << 1 | 1, max(l, mid + 1), r);return ans;
}
bool vis[1000002];
int main()
{fio();ll n,m;cin >> n >> m;ll ans = 0;ll an = 0;ll cnt = 0;for (ll i = 1; i <= n; i++){ll l, r;cin >> l >> r;if (l == -1){vis[i - 1] = 1;cnt++;ans += r;}a[i - 1] = { l,r };}if (cnt == -1)//全坏灯{cout << ans << endl;return 0;}build(1, 0, n - 1);while (m--){char x;cin >> x;if (x == 'W'){ll l, r;cin >> l >> r;u1(1, l, r);}else{ll l;cin >> l;an += p[1].gs * l;}}for (ll i = 0; i < n; i++){ll f = q(1, i, i);if (vis[i])continue;else an += a[i].second;}an += ans;cout << an << endl;
}
D. Quarantine Policy
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x%mod;}x = x*x % mod;y >>= 1;}return ans % mod ;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l, r;ll id;double f;friend bool operator<(const s& a, const s& b){if(fabs(a.f-b.f)<1e-9)return a.id<b.id;else return a.f> b.f;}
}p[2500];
ll a[333][330];
ll o[5]={1,0,-1,0};
ll e[5]={0,1,0,-1};
ll f1[5]={1,-1,1,-1};
ll f2[5]={1,-1,-1,1};
int main()
{fio();ll t;cin>>t;ll cs=0;while(t--){cs++;ll n,m;ll l,r;cin>>n>>m>>l>>r;string f[250];for(ll i=1;i<=n;i++)cin>>f[i],f[i]='0'+f[i];for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++)a[i][j]=0;}for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){if(f[i][j]=='V'){for(ll k=0;k<=3;k++){ll nx=i+o[k];ll ny=j+e[k];if(nx<1||nx>n||ny<1||ny>m)continue;a[nx][ny]=l;}for(ll k=0;k<=3;k++){ll nx=i+f1[k];ll ny=j+f2[k];if(nx<1||nx>n||ny<1||ny>m)continue;a[nx][ny]=max(a[nx][ny],r);}}}}cout<<"Airplane"<<" "<<"#"<<cs<<":"<<endl;for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){if(f[i][j]=='V')cout<<"V";else cout<<a[i][j];}cout<<endl;}cout<<endl;}
}
F.Baker's Dilemma
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
ll ksm(ll x, ll y)
{ll ans = 1;while (y){if (y & 1){ans = ans*x%mod;}x = x*x % mod;y >>= 1;}return ans % mod ;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l, r;ll id;double f;friend bool operator<(const s& a, const s& b){if(fabs(a.f-b.f)<1e-9)return a.id<b.id;else return a.f> b.f;}
}p[2500];
int main()
{fio();ll t;cin>>t;while (t--){ ll n;cin>>n;for(ll i=1;i<=n;i++){ll l,r;cin>>l>>r;p[i].l=l,p[i].r=r;p[i].id=i;p[i].f=(double)p[i].r/p[i].l;}sort(p+1,p+1+n);for(ll i=1;i<=n;i++){cout<<p[i].id<<" ";}cout<<endl;}
}
H.Bank Deposit Challenge
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int value[N];
int wei[N];
int dp[2000][150] = { 0 };
void solve() {int c;cin >> c;int x = 0;char n;int w = 0;int cnt = 0;n = getchar();while (1) {n = getchar();if (n == '\n') {if (cnt == 0) {value[++x] = w;}else {wei[++x] = w;}cnt++;if (cnt == 2) {break;}w = 0;if (cnt == 1) {x = 0;}continue;}if (n == ' ') {if (cnt == 0) {value[++x] = w;}else {wei[++x] = w;}w = 0;continue;}w = w * 10 + (n - '0');}for (int i = 1; i <= x; i++) {for (int j = c; j >= 0; j--) {//如果是01背包倒序遍历容量,无限个则正序遍历容量if (j < wei[i]) {dp[j][i] = dp[j][i - 1];//如果放不进来记得直接顺延}else {dp[j][i] = max(dp[j][i - 1], (dp[j - wei[i]][i - 1] + value[i]));}}}printf("%d", dp[c][x]);}
int main() {int t = 1;// scanf("%d",&t);while (t--) {solve();printf("\n");}return 0;
}
//2963628
L.Nine Never
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
void solve(){ll n;scanf("%lld",&n);if(n<9){printf("%lld",n);return ;}else{if(n%2==0){printf("%lld",(n/2)%mod);}else{if(n==11){printf("4");}else if(n==13){printf("5");}else if(n==15){printf("6");}else if(n==17){printf("8");}else if(n==19){printf("9");}else if(n==21){printf("9");}else if(n==23){printf("9");}else if(n==25){printf("9");}else if(n==27){printf("9");}else{printf("%lld",((n-11)/2+1)%mod);}}}}
int main(){int t=1;
// scanf("%d",&t);while(t--){solve();printf("\n");}return 0;
}
//2963628
M.Task scheduler
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;struct node{int id;int tim;int va;
}a[N];
bool cmp(node x,node y){if(x.va!=y.va){return x.va<y.va;}return x.tim<y.tim;
}
void solve(){int n;scanf("%d",&n);for(int i=1;i<=n;i++){a[i].tim=i;scanf("%d",&a[i].id);}for(int i=1;i<=n;i++){scanf("%d",&a[i].va);}sort(a+1,a+1+n,cmp);for(int i=1;i<=n;i++){if(i>1)printf(" ");printf("%d",a[i].id);}
}
int main(){int t;scanf("%d",&t);while(t--){solve();printf("\n");}return 0;
}
//2963628