A类--XCPCIO Board CLI Eay
(E)
题目分析:题目较长,涉及数据相较于其他题较多,待解决
B--BM 算期
(R)
思路:算出正确区间,for循环遍历,判断闰年
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,a,y;
cin>>t;
while(t--){
cin>>y>>a;
int b=y+a;
if(b>9999)b=9999-(b-9999);
if(b<y)swap(y,b);
int ans=0;
for(int i=y;i<=b;++i)
if(i%4==0&&i%100!=0||i%400==0)ans++;
cout<<ans<<'\n';
}
return 0;
}
C类--BBpigeon Counting Trees
(w)
分析:解决问题的实质是找上层节点每个节点分别连向了多少个下 层节点,待解决。
D--Palindrome Hard Problm
(R)
思路:单个字符即为一个回文串,将字符总数加起来即为数量最多的回文串
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
cin>>n;
int s=0;
for(int i=0;i<n;++i){
cin>>a;
s+=a.size();
}
cout<<s;
return 0;
}
E类--BM 饥
(R)
思路:无需解释
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
cin>>a;
cout<<" __ _____\n"
"| | ___/ ____\\____\n"
"| |/ /\\ __\\/ ___\\\n"
"| < | | \\ \\___\n"
"|__|_ \\ |__| \\___ >\n"
" \\/ \\/";
return 0;
}
F类--kita 买礼物
(w)
思路:多重背包用二进制优化为01背包。多重背包问题通常可转化成01背包问题求解。但若将每种物品的数量拆分成多个1的话,时间复杂度会很高,从而导致TLE。所以,需要利用二进制优化思想
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+5,M=1e9+7;
int n,m,v[N],b[N],a[100005];
bool f[N];
int main(){
cin>>n>>m;
for(int i=1;i<=n;++i)cin>>a[i];
int c=0;
for(int i=1;i<=n;++i){
int k,s=1;
cin>>k;
while(s<=k){
c++;
v[c]=a[i]*s;
k-=s;
s*=2;
}
if(k>0){
c++;
v[c]=a[i]*k;
}
}
n=c;
f[0]=true;
for(int i=1;i<=n;++i){
for(int j=m;j>=1;--j){
if(j>=v[i])
f[j]|=f[j-v[i]];
}
}
int ans=0;
for(int i=1;i<=m;++i){
ans+=f[i];
}
cout<<ans;
return 0;
}
G公司--New Gae
(E)
思路:拓扑排序
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+100;
const int inf=0x3f3f3f3f;
inline int rd() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch>'9') {
if (ch == '-')f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int t;
int n,m;
vector<int>ve[maxn],res;
int a,b,in[maxn];
signed main() {
t=rd();
while(t--) {
for(int i=1; i<=n; i++)ve[i].clear();
memset(in,0,sizeof in);
n=rd();
m=rd();
for(int i=1; i<=m; i++) {
a=rd();
b=rd();
ve[a].push_back(b);
in[b]++;
}
priority_queue<int,vector<int>,greater<int> >q;
for(int i=1; i<=n; i++) {
if(!in[i]) {
q.push(i);
}
}
while(!q.empty()) {
int u=q.top();
q.pop();
res.push_back(u);
for(int i=0; i<ve[u].size(); i++) {
int v=ve[u][i];
in[v]--;
if(!in[v]) {
q.push(v);
}
}
}
for(int i=0; i<res.size(); i++) {
if(i!=0)printf(" ");
printf("%lld",res[i]);
}
printf("\n");
res.clear();
}
return 0;
}
H--Hsueh-绘制度
(R)
思路:较简单
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
cin >>a;
for(int i=0;i<a;i++)
{
int m,n;
cin>>m>>n;
cout<<"[";
for(int j=0;j<n;j++)
cout<<"#";
for(int j=0;j<m-n;j++)
cout<<"-";
cout<<"] "<<100*n/m<<"%"<<endl;
}
return 0;
}
I--BM Tourim
(R)
思路:比较简单
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,s=0;
for(int i=0;i<4;i++){
cin>>a;
int b=0;
while(a)
{
b+=a%10;
a=a/10;
}
if(b==6||b>=16)
s++;
}
if(s==1)cout<<"Oh dear!!";
else if(s==2)cout<<"BaoBao is good!!";
else if(s==3)cout<<"Bao Bao is a SupEr man///!";
else if(s==4)cout<<"Oh my God!!!!!!!!!!!!!!!!!!!!!";
else cout<<"Bao Bao is so Zhai......";
return 0;
}
J型--general cleanig
(R)
思路:使用map函数对每一层楼出现过的相同字符数进行遍历和计数
#include<bits/stdc++.h>
using namespace std;
map<char,int>ma;
int main(){
int t,n,j,i,A[100],k=0;
cin>>t;
while(t--){
cin>>n;
int s=0;
string a;
for(i=1;i<=n;++i){
ma.clear();
cin>>a;
for(j=0;j<a.size();++j)
if(a[j]!='.'&&ma.count(a[j])==0){
s++;ma[a[j]]++;
}
}
A[k++]=s;
}
for(i=0;i<k;i++)
cout<<A[i]<<endl;
return 0;
}
K--Kwords查找Kth素
(E)
思路:晕
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int read(){
int x = 0 , ch = getchar();
while( ch < '0' || ch > '9' ) ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x;
}
int n,m,k;
int b[N];
bool check(int x,vector<int>c[]){
int cnt=0,q=0;
for(int i=0;i<m;++i){
q= upper_bound(c[b[i]-1].begin(),c[b[i]-1].end(),x)-c[b[i]-1].begin();
cnt+=q;
}
if(cnt>=k)return true;
return false;
}
int main(){
cin.tie(0),cout.tie(0);
n=read();
vector<int>a[n];
for(int i=0;i<n;++i){
m=read();
int x;
for(int j=0;j<m;++j){
x=read();
a[i].push_back(x);
}
}
for(int i=0;i<n;++i)sort(a[i].begin(),a[i].end());
int q;
q=read();
while(q--){
m=read();
for(int i=0;i<m;++i)cin>>b[i];
k=read();
int l=1,r=1e9;
while(l<r){
int mid=l+r>>1;
if(check(mid,a))r=mid;
else l=mid+1;
}
cout<<l<<'\n';
}
return 0;
}