Problem A Garbage Classification
https://ac.nowcoder.com/acm/contest/886/A
题意:
题解:模拟
C++版本一
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N];
char str[N],ss[27];
struct node{};
string s[4]={"Harmful","Recyclable","Dry","Wet"};
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
scanf("%d",&t);
int T=0;
while(t--){
scanf("%s%s",str,ss);
int len=strlen(str);
a[0]=a[1]=a[2]=0;
for(int i=0;i<len;i++){
if(ss[str[i]-'a']=='d')a[0]++;
if(ss[str[i]-'a']=='w')a[1]++;
if(ss[str[i]-'a']=='h')a[2]++;
}
cout<<"Case #"<<++T<<": ";
if(4*a[2]>=len){
cout<<s[0]<<endl;
}else if(10*a[2]<=len){
cout<<s[1]<<endl;
}else if(a[0]>=2*a[1]){
cout<<s[2]<<endl;
}else {
cout<<s[3]<<endl;
}
}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}
Problem B Shorten IPv6 Address
https://ac.nowcoder.com/acm/contest/886/B
题意:
题解:模拟
C++版本一
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int cnt,flag,temp,sum;
int a[N];
char str[N];
char tmp[N];
struct node{
string val;
bool operator <(const node S)const{
if(S.val.size()==val.size()){
return val<S.val;
}
return val.size()<S.val.size();
}
}ans[N];
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
scanf("%d",&t);
int T=0;
while(t--){
scanf("%s",str);
ans[0].val="";
for(int i=0;i<128;i+=16){
int id=i/16;
a[id]=0;
for(int j=0;j<16;j++){
if(str[i+j]=='1')a[id]=a[id]+(1<<(16-j-1));
}
sprintf(tmp,"%x",a[id]);
if(i==0) ans[0].val=tmp;
else ans[0].val+=':'+(string)tmp;
}
//cout<<ans[0].val<<endl;
cnt=0;
for(int i=0;i<8;i++){
l=i;
r=i;
if(a[i]==0&&(i==0||a[i-1]!=0)){
for(int j=i;j<8;j++){
if(a[j]==0)r=j;
else break;
}
if(r-l>=1){
cnt++;
ans[cnt].val="";
for(int j=0;j<8;j++){
sprintf(tmp,"%x",a[j]);
if(l<j&&j<r)
continue;
if(j==l||r==j){
ans[cnt].val+=':';
continue;
}
//printf("%x\n",a[j]);
if(j==0||j==r+1) ans[cnt].val+=tmp;
else ans[cnt].val+=':'+(string)tmp;
}
//cout<<ans[cnt].val<<" "<<l<<" "<<r<<endl;
}
}
}
sort(ans,ans+cnt+1);
cout<<"Case #"<<++T<<": "<<ans[0].val<<endl;
}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}
Problem C
题意:
题解:
C++版本一
Problem D Move
https://ac.nowcoder.com/acm/contest/886/D
题意:
题解:
C++版本一
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N];
int vis[N];
char str;
struct node{};
bool sloved(int mid){
memset(vis,0,sizeof(vis));
cnt=0;
for(int i=1;i<=k;i++){
int now=mid;
for(int j=n;j>=1;j--){
if(now>=a[j]&&!vis[j]){
now-=a[j];
vis[j]=1;
cnt++;
}
}
if(cnt>=n)break;
}
return cnt>=n;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
scanf("%d",&t);
int T=0;
while(t--){
scanf("%d%d",&n,&k);
sum=0;
int maxl=0;
for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i],maxl=max(maxl,a[i]);
sort(a+1,a+n+1);
l=max(maxl,(int)ceil(sum/k));
r=sum;
ans=sum;
for(int i=l;i<=r;i++)if(sloved(i)){ ans=i;break;}
cout<<"Case #"<<++T<<": "<<ans<<endl;
}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}
Problem E
题意:
题解:
C++版本一
Problem F
题意:
题解:
C++版本一
Problem G
题意:
题解:
C++版本一
Problem H
题意:
题解:
C++版本一
Problem I
题意:
题解:
C++版本一
Problem J Upgrading Technology
https://ac.nowcoder.com/acm/contest/886/J
题意:
题解:
C++版本一