感觉这次出题怪怪的......做了5道但是感觉很不爽
C直接暴力枚举状态然后check,D是一道蜜汁贪心,现在也不知道咋证明,E差不多就模板题,一个点被卡了精度还调了好久......
F考了一点逆向思维?直接算不好算所以先算一开始一条边都没有的时候答案是多少,然后考虑每加一条边答案会减去多少,看起来像树形dp的一道题不到10行就弄完了......虽然确实挺巧的,但感觉AtCoder出题日渐趋向脑筋急转弯?
P.S. E题代码参考了这篇blog,这个n选K乘积最大就当模板记下来了
A
#include
#include
#include
#include
using namespace std;
typedef long long ll;
inline int read() {
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int main() {
int n=read();
if (n%1000==0) puts("0");
else printf("%d\n",1000-n%1000);
return 0;
}
B
#include
#include
#include
#include
#include
C
#include
#include
#include
#include
using namespace std;
typedef long long ll;
int n,m,K;
inline int read() {
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
char mp[7][7],tmp[7][7];
int ans;
inline void paint(int str,int stc) {
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
tmp[i][j]=mp[i][j];
for (int i=1;i<=n;++i)
if (str&(1<<(i-1))) {
for (int j=1;j<=m;++j)
tmp[i][j]='r';
}
for (int j=1;j<=m;++j)
if (stc&(1<<(j-1))) {
for (int i=1;i<=n;++i)
tmp[i][j]='r';
}
}
inline int count() {
int ret=0;
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
ret+=(tmp[i][j]=='#');
return ret;
}
int main() {
n=read(),m=read(),K=read();
for (int i=1;i<=n;++i)
scanf("%s",mp[i]+1);
for (int str=0;str<(1<
D
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N=2e5+4;
int n;
ll a[N];
inline int read() {
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
inline bool cmp(int x,int y) {
return x>y;
}
int main() {
n=read();
for (register int i=1;i<=n;++i) a[i]=read();
sort(a+1,a+n+1,cmp);
ll ans=a[1];
int pos=2;
for (int i=3;i<=n;++i) {
// printf("%d %d\n",a[i],a[pos]);
ans+=a[pos];
if (!(i&1)) ++pos;
}
cout<
E
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
int n,k;
ll ans=1;
int l_neg=-1,l_pos=-1,r_neg=-1,r_pos=-1;
const ll M=1e9+7;
inline bool cmp(ll a, ll b) {
return abs(a) a) {
ll ret=1;
for(int i = n - k; i < n; i++)
(ret*=a[i])%=M;
return ret;
}
inline int read() {
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int main() {
n=read(),k=read();
vector a(n,0);
for (register int i=0;i0) r_pos=i;
if (r_neg==-1&&a[i]<0) r_neg=i;
}
for (register int i=n-k-1;~i;--i) {
if(l_pos==-1&&a[i]>0) l_pos=i;
if(l_neg==-1&&a[i]<0) l_neg=i;
}
if (ans<0&&n>k) {
if (r_pos==-1) {
if (l_pos==-1) {
ans=1;
for (int i=0;i c1=a;
vector c2=a;
swap(c1[l_neg],c1[r_pos]);
swap(c2[l_pos],c2[r_neg]);
// ans==v_cmp(c1, c2)==true? calc(c1): calc(c2);
ans=(abs(a[l_neg]*a[r_neg])>abs(a[l_pos]*a[r_pos]))?calc(c1):calc(c2);
}
}
}
cout<<(ans%M+M)%M<
F
#include
#include
#include
#include
using namespace std;
const int N=2e5+4;
typedef long long ll;
int n;
ll ans;
inline int read() {
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int main() {
n=read();
for (register int i=1;i<=n;++i)
ans+=1ll*i*(n-i+1);
for (register int i=1;iv) u^=v^=u^=v;
ans-=1ll*u*(n-v+1);
}
cout<