B:判断奇数堆的数量为奇数输出n否则0
#include
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn=100000+5;
int n,s[maxn];
int main()
{
cin>>n;
int ever=0,odd=0;
for(int i=1;i<=n;++i)
{
cin>>s[i];
if(s[i]%2){odd++;}
else {ever++;}
}
if(odd%2){cout<
D:排序按每次可减少的钱最少优秀
#include
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn=100000+5;
int n;
struct Node
{
int a;
double p;
bool operator < (const Node &b)const{
return a*(1-b.p)>n;
for(int i=1;i<=n;++i){cin>>node[i].a>>node[i].p;}
sort(node+1,node+1+n);
double ans=0;
double p=1;
for(int i=1;i<=n;++i)
{
ans+=node[i].a*p;
p*=node[i].p;
}
printf("%.6f\n",ans);
return 0;
}
F:二分搜索下搜索第一个小于L,上搜索第一个大于R
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn = 100000 + 5;
struct Circle {
int l, r;
}cir1[maxn], cir2[maxn];
int n;
int cmp1(Circle a, Circle b)
{
if (a.l == b.l) { return a.r < b.r; }
return a.l < b.l;
}
int cmp2(Circle a, Circle b)
{
if (a.r == b.r) { return a.l < b.l; }
return a.r < b.r;
}
int find1(double tm)
{
int l = 1, r = n;
while (l <= r)
{
int mid = (l + r) / 2;
if (cir2[mid].r >= tm) { r = mid - 1; }
else { l = mid + 1; }
}
while (r > 0 && cir2[r].r >= tm) { r--; }
return r;
}
int find2(double tm)
{
int l = 1, r = n;
while (l <= r)
{
int mid = (l + r) / 2;
if (cir1[mid].l <= tm) { l = mid + 1; }
else { r = mid - 1 ; }
}
while (cir1[l].l <= tm&&l<=n) { l++; }
return n - l+1;
}
int main()
{
cin >> n;
double p, r;
for (int i = 1; i <= n; ++i)
{
cin >> p >> r;
cir1[i].l = cir2[i].l = p - r;
cir1[i].r = cir2[i].r = p + r;
}
sort(cir1+1, cir1 + n+1, cmp1);
sort(cir2+1, cir2 + n+1, cmp2);
int sum = 0;
for (int i = 1; i <= n; ++i)
{
sum += find2(cir1[i].r);
}
cout << sum<< endl;
return 0;
}
G:纯模板严格单调递增子序列
#include
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn=50000+5;
int n,s[maxn],dp[maxn];
void LCS()
{
int len=0;
dp[0]=s[1];
for(int i=1;i<=n;++i)
{
if(s[i]>dp[len]){dp[len+1]=s[i];len++;}
else
{
int t=lower_bound(dp,dp+len,s[i])-dp;
dp[t]=s[i];
}
}
cout<>n;
for(int i=1;i<=n;++i)
{
cin>>s[i];
}
LCS();
return 0;
}
I:排序暴力直接跑
#include
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn=100000+5;
struct Node{
int a;
int b;
}node[maxn];
int n,a1;
int cmp(Node a,Node b)
{
if(a.a==b.a){return a.b>b.b;}
return a.a>b.a;
}
int main()
{
cin>>n>>a1;
for(int i=1;i>node[i].a;}
for(int i=1;i>node[i].b;}
int ans=a1;
int flag=1;
while(flag)
{
flag=0;
for(int i=1;inode[i].a){continue;}
flag=1;
while(ans>=0&&node[i].a>=ans)
{
ans--;
node[i].a-=node[i].b;
}
if(ans<0){break;}
}
if(ans<0){break;}
}
if(ans>=0){cout<