CF569A
题意 定义第一阶菱形是一个正方形 n阶就是n-1阶菱形表面有多少个边加多少个
一开始没看懂题 以为中间是正方形 盲猜了一发 n==1?1:(2n-2)(2*n-2)+4;
后来发现其实规律是 ans[i] = ans[i-1]+(i-1)*4
因为每次多贡献四个边
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){
int ans=1;while(b){
if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){
return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){
if(!b) {
d = a;x = 1;y=0;}else{
exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
int ans[500];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
ans[1] = 1;
for(int i = 2;i<=100;++i)
{
ans [i] = ans[i-1]+(i-1)*4;
}
printf("%d\n",ans[n]);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
cf569B
这题也蛮有意思
给你n长度的数组 你可以把一项 arr[i] 变为 -arr[i] - 1
问你乘积最大的时候数组长啥样
做法不难发现一个数只有是负数的时候绝对值最大
所以我们取偶数个负数使得他绝对值最大而且又为正数
我们首先把数组所有元素转换成负数 因为-arr[i]-1保证负数存在
如果一个数组是偶数长度 我们直接取所有负数
否则我们取 n-1 个负数 并且让绝对值最大的负数变成正数
举个例子 -6 转换一下是 5
那么你少乘一个6变成乘一个5
答案变成原答案绝对值 5/6
但是你 -2 转换一下是1
少乘一个2变成乘一个1
答案变成原答案绝对值 1/2 显然亏了
所以把最小的负数转换即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){
int ans=1;while(b){
if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){
return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){
if(!b) {
d = a;x = 1;y=0;}else{
exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 100025;
int arr[MAX_N];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
for(int i = 1;i<=n;++i)
scanf("%d",