Codeforces Round #797 (Div. 3)
Posted yeah17981
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #797 (Div. 3)相关的知识,希望对你有一定的参考价值。
关于有的脑子有病的人,怕丢脸就都没提交,结果最后一分钟脑子一缺全交上去,然后没交成功……
A:初始高度为321,从高到低循环加高度
B:有读错题的笨蛋~~
一个数组a和一个数组b,a的元素每次都-1,如果ai=0就不减这一位,问能不能改成b,但是有笨蛋排序比最大值去了(虽然最后看对题后还wa了一发就是说)
C:从前往后模拟,记录现在的结束点,然后更新,ok
D:笨蛋卡了一会,只需要求连续一段k中间有几个w就ok
E:先把每个数除以k,这一部分是一定能在结果中的,剩下了一堆<k的数字,找到其中俩俩结合。排序,如果有刚好的能结合的,就结合,如果没有的话,找有没有剩下的更大的结合。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<bitset>
#include<limits.h>
//#pragma GCC optimize (2)
//#pragma G++ optimize (2)//手动开O2
#define ls (p<<1)//线段树左儿子
#define rs (p<<1|1)//线段树右儿子
#define mid (l+r>>1)//线段树mid
#define gc() getchar()
//#define int __int128//水大数
using namespace std;
#undef mid
typedef long long ll;
typedef unsigned long long ull;//卡精度
typedef pair<int, int> PII;
const int N = 2e5 + 7;
const ll mod = 1e9 + 7;
const ll INF = 1e15 + 7;
const double EPS = 1e-10;//可近似为趋近为 0 可以根据定义求导时使用
const int base = 131;//base = 13331 // hash
const int maxn = 100;
inline ll read()
ll a = 0; int f = 0; char p = gc();
while (!isdigit(p)) f |= p == '-'; p = gc();
while (isdigit(p)) a = (a << 3) + (a << 1) + (p ^ 48); p = gc();
return f ? -a : a;
ll a[N];
ll k1[1001];
int main()
ll _,n,k;
_=read();
while(_--)
ll ans=0;
memset(k1,0,sizeof k1);
n=read(),k=read();
for(int i=1;i<=n;i++)
a[i]=read();
ans+=a[i]/k;
k1[a[i]%k]++;
// sort(b+1,b+1+n);
ll ch=0;
ll pos=0;
for(int i=1;i<k;i++)
if(i>k-i) break;
if(i==k-i)
pos=k1[i]/2;
pos=min(k1[i],k1[k-i]);
ans+=pos;
k1[i]-=pos;
k1[k-i]-=pos;
if(k1[k-i]>0)
ch+=k1[k-i];
else
if(k1[i]>=ch)
ans+=ch;
ch=0;
else
ans+=k1[i];
ch-=k1[i];
cout<<ans+ch/2<<"\\n";
F:把数字序列处理成有向图,其中有k个有向环,则结果是lcm(每个环的最小循环节)
通过暴力求出每个环的最小循环节,结束
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<bitset>
#include<limits.h>
//#pragma GCC optimize (2)
//#pragma G++ optimize (2)//ÊÖ¶¯¿ªO2
#define ls (p<<1)//Ï߶ÎÊ÷×ó¶ù×Ó
#define rs (p<<1|1)//Ï߶ÎÊ÷ÓÒ¶ù×Ó
#define mid (l+r>>1)//Ï߶ÎÊ÷mid
#define gc() getchar()
//#define ll __int128//Ë®´óÊý
using namespace std;
#undef mid
typedef long long ll;
typedef unsigned long long ull;//¿¨¾«¶È
typedef pair<ll, ll> PII;
const ll N = 202;
const ll mod = 1e9 + 7;
const ll INF = 1e15 + 7;
const double EPS = 1e-10;//¿É½üËÆΪÇ÷½üΪ 0 ¿ÉÒÔ¸ù¾Ý¶¨ÒåÇóµ¼Ê±Ê¹ÓÃ
const ll base = 131;//base = 13331 // hash
const ll maxn = 100;
inline ll read()
ll a = 0; ll f = 0; char p = gc();
while (!isdigit(p)) f |= p == '-'; p = gc();
while (isdigit(p)) a = (a << 3) + (a << 1) + (p ^ 48); p = gc();
return f ? -a : a;
ll k[202];
char q[202];
bool f[202];
ll gcd(ll a, ll b)
if (b == 0)
return a;
return gcd(b, a % b);
ll lcm(ll a,ll b)
return a/(gcd(a,b))*b;
int main()
ll _,n;
_=read();
while(_--)
memset(f,0,sizeof f);
n=read();
cin>>q;
for(ll i=0;i<n;i++)
cin>>k[i];
k[i]--;
ll ans=1;
for(ll i=0;i<n;i++)
string s;
if(f[i]) continue;
for(ll j=i;!f[j];j=k[j])
f[j]=1;
s+=q[j];
//s+=j+'0';
ll m = s.length();
bool flag=0;
for(ll j=1;j<m;j++)
if(m%j!=0) continue;
flag=0;
for(ll h=0;h<m;h++)
if(s[(h+j)%m]!=s[h])
flag=1;
break;
if(flag==0)
m=j;
break;
ans =lcm(ans, m);
cout<<ans<<"\\n";
cout<<"\\n";
以上是关于Codeforces Round #797 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #797 (Div. 3)
Codeforces Round 797 (Div. 3,CF1690)全题解
Codeforces Round 797 (Div. 3,CF1690)全题解
Codeforces Round #436 E. Fire(背包dp+输出路径)