SDUT 2021 Spring Team Contest--- 11(Kattis)题解
作者:互联网
Kattis
B - Baby Bites
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int dp[N];
void solve(){
int n;
cin>>n;
bool flag=0;
for(int i=1;i<=n;i++){
string s;
cin>>s;
if(s=="mumble") continue;
else {
int num=stoi(s);
if(num!=i){
flag=1;
}
}
}
if(flag) cout<<"something is fishy"<<endl;
else cout<<"makes sense"<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
C - Code Cleanups
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 410;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
//int dp[M];
vector<int> col(M);
vector<int> vis(M);
void solve(){
int n;
cin>>n;
int k;
for(int i=0;i<n;i++){
cin>>k;
vis[k]++;
}
int tot=0;
for(int i=1;i<400;i++){
if(col[i-1]+vis[i-1]>=20){
col[i-1]=vis[i-1]=0;
tot++;
}
col[i]+=(col[i-1]+vis[i-1]);
vis[i]+=vis[i-1];
}
cout<<tot<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
H - House Lawn
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 410;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
vector<string>vp;
void solve(){
double l;
int m;
cin>>l>>m;
string s;
int minn=inf;
while(m--){
getchar();
s="";
char k;
while(1){
k=getchar();
if(k==',') break;
s+=k;
}
int p;
double c,t,r;
scanf("%d,%lf,%lf,%lf",&p,&c,&t,&r);
if(p<minn&&t/(t+r)*c*10080>=l){
minn=p;
vp.clear();
vp.pb(s);
}
else if(p==minn&&t/(t+r)*c*10080>=l){
vp.pb(s);
}
}
if(minn==inf) cout<<"no such mower"<<endl;
else{
for(int i=0;i<(int)vp.size();i++){
cout<<vp[i]<<endl;
}
}
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
solve();
return 0;
}
I - Intergalactic Bidding
答案
#include <bits/stdc++.h>
typedef long long ll;
const int N = 1e3 + 7;
using namespace std;
struct xrr {
char x[1005]; int len;string s;
bool operator == (const xrr &A) const {
if(A.len != len) return 0;
for(int i = 0; i < len; ++i) if(A.x[i] != x[i]) return 0;
return 1;
}
bool operator < (const xrr &A) const {
if(A.len != len) return len < A.len;
for(int i = len-1; i >= 0; --i) if(A.x[i] != x[i]) return x[i] < A.x[i];
return 0;
}
xrr operator + (const xrr &A) const {
xrr ans = *this;
for(int i = 0; i < A.len; ++i) {
ans.x[i] = ans.x[i] + A.x[i];
}
int mx = max(A.len, len), f = 0;
for(int i = 0; i < mx+1; ++i) {
if(ans.x[i] >= 10) {
ans.x[i]-=10; ++ans.x[i+1];
}
if(ans.x[i]) ans.len = i+1, f = 1;
}
if(!f) ans.len = 1;
return ans;
}
xrr operator - (const xrr &A) const {
xrr ans = *this; int f = 0;
for(int i = 0; i < A.len; ++i) {
ans.x[i] = ans.x[i] - A.x[i];
}
int mx = max(A.len, len);
for(int i = 0; i < mx+1; ++i) {
if(ans.x[i] < 0) {
ans.x[i]+=10; --ans.x[i+1];
}
if(ans.x[i]) ans.len = i+1, f = 1;
}
if(!f) ans.len = 1;
return ans;
}
void read() {
cin >> s; len = s.size();
for(int i = 0; i < len; ++i) x[len-i-1] = s[i]-'0';
s.clear();
}
void write() {
for(int i = len-1; i >= 0; --i) printf("%d",x[i]); putchar('\n');
}
} s, xtt;
int n;
struct node{
string nm; xrr A;
bool operator < (const node & a) const {
return A < a.A;
}
} a[N];
vector<int> ans;
int main() {
xtt.x[0] = 0; xtt.len = 1;
scanf("%d",&n);
s.read();
for(int i = 1; i <= n; ++i) {
cin >> a[i].nm; a[i].A.read();
}
sort(a+1,a+1+n);
for(int i = n ; i >= 1; --i) {
if( a[i].A < s || s == a[i].A) {
ans.push_back(i);
s = s - a[i].A;
}
}
if(s == xtt) {
printf("%d\n",(int)ans.size());
for(int i = 0; i < ans.size(); ++i) {
cout << a[ans[i]].nm << '\n';
}
}
else puts("0");
return 0;
}
J - Jumbled String
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
const double eps = 1e-6;
const int mod = 998244353;
const int N = 1e6 + 10;
const int M = 410;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
vector<string>vp;
void solve(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
if(!a&&!b&&!c&&!d){
cout<<"0"<<endl;
return ;
}
ll x=(sqrt(1+8*a)+1)/2;
ll y=(sqrt(1+8*d)+1)/2;
if(x*(x-1)>>1!=a||y*(y-1)>>1!=d){
cout<<"impossible"<<endl;
return ;
}
if(!a&&!d){
if(b==1&&!c) cout<<"01"<<endl;
else if(!b&&c==1) cout<<"10"<<endl;
else cout<<"impossible"<<endl;
return ;
}
if(!b&&!c){
if(!a){
for(ll i=1;i<=y;i++){
cout<<"1";
}
cout<<endl;
}
else if(!d){
for(ll i=1;i<=x;i++){
cout<<"0";
}
cout<<endl;
}
else cout<<"impossible"<<endl;
return ;
}
if(x*y!=b+c){
cout<<"impossible"<<endl;
return ;
}
ll xx=b/y;
ll yy=b%y;
for(ll i=1;i<=xx;i++) cout<<"0";
for(ll i=1;i<=y-yy;i++) cout<<"1";
if(xx!=x) cout<<"0";
for(ll i=1;i<=yy;i++) cout<<"1";
for(ll i=1;i<x-xx;i++) cout<<"0";
cout<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
标签:11,const,Kattis,int,题解,len,long,ans,define 来源: https://blog.csdn.net/qq_45830025/article/details/116333537