AtCoder Beginner Contest 331
这场状态好差,下午的校赛也打的好差。
A - Tomorrow
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
int M,D;
int y,m,d;
cin>>M>>D>>y>>m>>d;
d++;
if(d>D){
m++;
d=1;
}
if(m>M){
y++;
m=1;
}
cout<<y<<" "<<m<<" "<<d;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
B - Buy One Carton of Milk
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
int n;
cin>>n;
int a,b,c;
cin>>a>>b>>c;
int ans=99999999999;
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
for(int k=0;k<20;k++){
if(6*i+8*j+k*12>=n) ans=min(ans,a*i+j*b+k*c);
}
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
C - Sum of Numbers Greater Than Me
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int a[N],b[N];
int pre[N];
int n;
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
}
sort(b+1,b+1+n);
for(int i=1;i<=n;i++) pre[i] = pre[i-1] + b[i];
for(int i=1;i<=n;i++){
int idx=upper_bound(b+1,b+1+n,a[i])-b;
cout<<pre[n]-pre[idx-1]<<" ";
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
D - Tile Pattern
写的时候感觉这道题好狗屎,就没打了放弃了。
本来以为是我的想法挺粪的,看了下佬的码发现大家 写的其实都挺粪的。
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int P[5010][5010];
int n,q;
void solve(){
cin>>n>>q;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
char c;
cin>>c;
P[i][j]=(c=='B');
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
P[i][j] += P[i-1][j] + P[i][j-1] - P[i-1][j-1];
while(q--){
int a,b,c,d;
cin>>a>>b>>c>>d;
int len=c-a+1;
int wid=d-b+1;
a%=n,b%=n,c%=n,d%=n;
a++,b++,c++,d++;
if(a > 1) len += a - 1;
if(c < n) len += n - c;
if(b > 1) wid += b - 1;
if(d < n) wid += n - d;
int ans=0;
ans += P[a - 1][n] * (wid / n);
ans += (P[n][n] - P[c][n]) * (wid / n);
ans += P[n][b - 1] * (len / n);
ans += (P[n][n] - P[n][d]) * (len / n);
ans -= P[a - 1][b - 1];
ans -= P[n][b - 1] - P[c][b - 1];
ans -= P[a - 1][n] - P[a - 1][d];
ans -= P[n][n] + P[c][d] - P[c][n] - P[n][d];
ans = P[n][n] * (len / n) * (wid / n) - ans;
cout << ans << endl;
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
E - Set Meal
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
struct node{
int x,y;
int val;
friend bool operator <(node a,node b){
return a.val<b.val;
}
};
const int N = 1e5 + 10;
set<int> path[N];
void solve(){
int n,m,l;
cin>>n>>m>>l;
vector<pair<int,int>> a,b;
for(int i=1;i<=n;i++){
int x;
cin>>x;
a.push_back({x,i});
}
for(int i=1;i<=m;i++){
int x;
cin>>x;
b.push_back({x,i});
}
for(int i=1;i<=l;i++){
int u,v;
cin>>u>>v;
path[u].insert(v);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
priority_queue<node> que;
que.push({n-1,m-1,a[n-1].first+b[m-1].first});
set<pair<int,int>> vis;
vis.insert({n-1,m-1});
while(que.size()){
node u=que.top();
que.pop();
int aa=a[u.x].second;
int bb=b[u.y].second;
if(path[aa].find(bb)==path[aa].end()){
cout<<u.val<<endl;
return;
}
if(u.x>=0&&u.y-1>=0&&!vis.count({u.x,u.y-1}))
{
que.push({u.x,u.y-1,a[u.x].first+b[u.y-1].first});
vis.insert({u.x,u.y-1});
}
if(u.x-1>=0&&u.y>=0&&!vis.count({u.x-1,u.y}))
{
que.push({u.x-1,u.y,a[u.x-1].first+b[u.y].first});
vis.insert({u.x-1,u.y});
}
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
}
F - Palindrome Query
线段树下次再补吧
标签:AtCoder,Beginner,int,331,cin,long,solve,ans,define From: https://www.cnblogs.com/zfxyyy/p/17875703.html