首页 > 其他分享 >团队练习记录2024.9.28

团队练习记录2024.9.28

时间:2024-09-28 18:34:17浏览次数:5  
标签:ch -- 2024.9 ll 练习 28 ++ while ans

B - Magical Subsequence

https://codeforces.com/gym/103447/problem/B
桶+stack,这里用map会TLE
stack用一次时间复杂度\(O(1)\)
\(156ms/1000ms\)

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void fio()
{
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
}
ll ksm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1)
		ans*=x;
		x*=x;
		y>>=1;
	}
	return ans;
}
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-') 
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}
ll a[250000];
ll n;
ll ck(ll x)
{
	stack<ll>q;
	ll b[250]={0};
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]<x)
		{
			if(b[x-a[i]]>0)
			{
				ans++;
				while(!q.empty())
				{
					b[q.top()]=0;
					q.pop();
				}
				continue;
			}
			else
			{
				if(b[a[i]]==0)
				{
					q.push(a[i]);
				}
				b[a[i]]++;
			}
		}
	}
	return ans*2;
}
int main()
{
cin>>n;;
for(ll i=1;i<=n;i++)a[i]=read();
ll ans=0;
for(ll i=1;i<=200;i++)
{
	ans=max(ans,ck(i));
}
printf("%lld\n",ans);
} 

D. Math master

https://codeforces.com/gym/103447/problem/D
先用gcd求出最小的比例形式,然后暴力求出一个数的所有可能组合,时间复杂度为最差在2的18次方左右?
sort一遍储存的数
然后直接check查出另一个答案是否符合题目要求
第一个符合的最小的即为所求。
\(3171ms/4000ms\)

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
typedef  long long ll;
void fio()
{
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
}
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	else
		return gcd(y, x % y);
		
}
ll ksm(ll x, ll y)
{
	ll ans = 1;
	while (y)
	{
		if (y & 1)
			ans *= x;
		x *= x;
		y >>= 1;
	}
	return ans;
}
/*
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}*/
ll a[3500000];
ll l = 0;
void zu(string x,ll wz,ll su)
{
	for (ll i = wz + 1; i < x.size(); i++)
	{
		zu(x, i, su * 10 + x[i] - '0');
	}
	if (su > 0)
	{
		l++;
		a[l] = su;
	}
}
bool ck(string a, string b, string a1, string b1)
{
	ll num[15] = { 0 };
	ll num2[15] = { 0 };
	ll la = a.length() - 1, la1 = a1.length() - 1, lb = b.length() - 1, lb1 = b1.length() - 1;

	while (la1 >= 0) {
		if (la < 0) {
			if (a1[la1] == '0' && la < 0) {
				num[10]++;
				la1--;
				continue;
			}
			num[a1[la1] - '0']++;
			la1--;
			continue;
		}

		if (a[la] == a1[la1]) {
			la--, la1--;
			continue;
		}
		else {
			num[a1[la1] - '0']++;
			la1--;
		}
	}
	while (lb1 >= 0) {
		if (lb < 0) {
			if (b1[lb1] == '0' && lb < 0) {
				num2[10]++;
				lb1--;
				continue;
			}
			num2[b1[lb1] - '0']++;
			lb1--;
			continue;
		}
		if (b[lb] == b1[lb1]) {
			lb--, lb1--;
			continue;
		}
		else {
			num2[b1[lb1] - '0']++;
			lb1--;
		}
	}
	ll flag = 1;
	for (int i = 0; i <= 9; i++) {
		if (i == 0) {
			ll mini = min(num[0] + num[10], num2[0] + num2[10]);
			if (mini < max(num[0], num2[0])) {
				flag = 0;
			}
		}
		else if (num[i] != num2[i]) {
			flag = 0;
		}
	}
	if (flag) return true;
	else return false;
}
int main()
{
	fio();
	ll t;
	t = 1;
	while (t--)
	{
		ll n;
		cin >> n;
		for (ll i = 1; i <= n; i++)
		{
			ll x, y;
			cin >> x >> y;
			ll k = gcd(x, y);
			ll x1 = x / k;
			ll y1 = y / k;
			string h = to_string(x);
			string e = to_string(y);l = 0;
			for (ll u = 0; u < h.size(); u++)
			{
				zu(h, u, h[u] - '0');
			}
			//for (ll i = 1; i <= l; i++)cout << a[i] << " ";
			sort(a + 1, a + 1 + l);
			ll ans1=0, ans2=0;
			for (ll i = 1; i <= l; i++)
			{
				if (a[i] % x1 == 0)
				{
					ll k1 = a[i] / x1;
					ll y2 = y1*k1;
					string jk = to_string(a[i]);
					string ko = to_string(y2);
					if (ck(jk,ko,h,e))
					{
						ans1 = a[i], ans2 = y2;
						break;
					}
				}
			}
			cout << ans1 << " " << ans2 << endl;
		}
	}
}

E. Power and Modulo

https://codeforces.com/gym/103447/problem/E
打表可得,如果2的次方被模后会呈现一个周期,要特判后面为为0,全部数为0,数组对应位置大于2的次方的情况
然后直接找到第一个变小的数字,然后用对应的数的次方减掉它即为模数
\(218ms/1000ms\)

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
void fio()
{
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
}
ll ksm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1)
		ans*=x;
		x*=x;
		y>>=1;
	}
	return ans;
}
/*
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-') 
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}*/
ll a[120000];
int main()
{
	fio();
	ll t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll g=0;
		ll op=0;
		for(ll i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0)
			op++;
			if(g)
			{
				if(a[i]>0)
				{
					g=-1;
				}
			}
			if(a[i]==0&&g==0)
			{
				g=1;
			}
		}
		if(op==n)
		{
			cout<<1<<endl;
			continue;
		}
		if(g==-1)
		{
			cout<<-1<<endl;
			continue;
		}
		ll cnt=1;
		ll x=0;
		for(ll i=1;i<=n;i++)
		{
			if(a[i]!=cnt)
			{
			x=cnt-a[i];
			break;	
			}
			cnt*=2;
		}
		if(x<0)
		{
			cout<<-1<<endl;
			continue;
		}
		if(x==0)
		{
			x=a[n];
		}
		 cnt=1;
		g=0;
		cnt%=x;
		for(ll i=1;i<=n;i++)
		{
			if(a[i]!=cnt)
			{
	     	g=-1;		
			}
			cnt=(cnt%x*(2%x))%x;
		}
		if(g==-1)
		{
			cout<<-1<<endl;
		}
		else
		{
			cout<<x<<endl;
		}
	}
}

I. Power and Zero

https://codeforces.com/gym/103447/problem/I
二进制转换+暴力
记得没事不开\(unsigned long long\)
\(249ms/1000ms\)

#include<iostream>
using namespace std;
typedef  long long ll;
void fio()
{
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
}
ll ksm(ll x, ll y)
{
	ll ans = 1;
	while (y)
	{
		if (y & 1)
			ans *= x;
		x *= x;
		y >>= 1;
	}
	return ans;
}
/*
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}*/
ll a[40];
int main()
{
	fio();
	ll t;
	cin >> t;
	//	cout<<55<<endl;
	while (t--)
	{
		ll n;
		cin >> n;
		for (ll i = 0; i <= 31; i++)a[i] = 0;
		for (ll i = 1; i <= n; i++)
		{
			ll x;
			cin >> x;
			ll k = 1;
			for (ll j = 0; j <= 31; j++)
			{
				if (k & x)
					a[j]++;
				k *= 2;
			}
		}
		ll ans = 0;
		while (1)
		{
			ll cnt = 0;
			for (ll i = 0; i <= 31; i++)
			{
				if (a[i] == 0)
					cnt++;
			}
			if (cnt == 32)
				break;
			ans++;
			for (ll i = 0; i <= 31; i++)
			{
				if (a[i] > 0)
				{
					a[i]--;
				}
				else
				{
					for (ll j = i + 1; j <= 31; j++)
					{
						if (a[j] > 0)
						{
							a[j]--;
							for(ll k = j - 1; k >= 0; k--)
							{
								if (k >= i)
								{
									a[k]++;
								}
								else
								{
									break;
								}
							}
							break;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

J. Local Minimum

https://codeforces.com/gym/103447/problem/J
统计一个数既为此行最小和此列最小的数
这里加速流会TLE,要用快读
\(203ms/1000ms\)

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void fio()
{
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
}
ll ksm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1)
		ans*=x;
		x*=x;
		y>>=1;
	}
	return ans;
}
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-') 
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}
ll a[2500][2500];
ll b[2500];
ll c[2500];
int main()
{
	ll n,m,f;
	n=read();
	m=read();
	for(ll i=1;i<=n;i++)
	{
		ll x=99999999999;
		for(ll j=1;j<=m;j++)
		{
			a[i][j]=read();
			x=min(x,a[i][j]);
		}
		b[i]=x;
	}
     for(ll i=1;i<=m;i++)
	{
		ll x=99999999999;
		for(ll j=1;j<=n;j++)
		{
			x=min(x,a[j][i]);
		}
		c[i]=x;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if(b[i]==a[i][j]&&c[j]==a[i][j])
			ans++;
		}
	}
	printf("%lld\n",ans);
} 

标签:ch,--,2024.9,ll,练习,28,++,while,ans
From: https://www.cnblogs.com/cjcf/p/18438256

相关文章

  • mysql 0928 DDL表操作
    `ALTERTABLEempaddnicknameVARCHAR(20)COMMENT'昵称';--添加字段nicknameDESCTABLEemp;--查看表ALTERTABLEempMODIFYnicknamevarchar(10);--修改数据类型ALTERTABLEempchangenicknameusernameVARCHAR(30);--修改字段nickname为usernameALT......
  • 9.28
    最小化\[2\sqrt{5-4\cos\theta}+\sqrt{5-4\sin\theta}\]可化为\[\begin{aligned}&2\sqrt{5-4\cos\theta}+\sqrt{5-4\sin\theta}\\=&\sqrt{20-16\cos\theta}+\sqrt{5-4\sin\theta}\\=&\sqrt{(2\cos\theta-4)^2+(2\sin\theta)......
  • INF80028 - Business Process Management
    INF80028- Business Process ManagementSemester2,2024Assignment2AnalysingandDesigningTo-BeBusinessProcess forSwinburneCaresFoundationAssignment2dueon Week12Friday18th Oct.at23:59 AEDST Assessment2 Value=40%Tobecompletedi......
  • gjoi 2024.9.27
    assert(0);不嘻嘻。T1棋局首先不难列出dp方程\(f[i][j]\)表示玩了\(i\)局A赢了\(j\)局的方案数(我们这里钦定玩了\(R_m+R_h\)局A赢了\(R_m\)局),转移\(f[i][j]\times\frac{j}{i}\tof[i+1][j+1],f[i][j]\times\frac{i-j}{i}\tof[i+1][j]\),仔细思考/画图/大眼......
  • 9.28日报
    p37动手动脑输出结果为:falsefalsetrueSMALLMEDIUMLARGE第一行 false 是因为 s 和 t 是不同的枚举实例。第二行 false 是因为枚举不是原始类型。第三行 true 是因为 s 和 u 是相同的枚举实例。接下来的三行分别打印出枚举 Size 的所有成员: SMALL 、 ......
  • 9.28日随笔
    动手动脑P37枚举不属于原始数据类型,它的每个具体值都引用一个特定的对象。相同的值则引用同一个对象,可以使用“”和equals()方法直接比对枚举变量的值,对于枚举类型的变量,“”和equals()方法执行的结果是等价的,枚举为引用类型得到结果为falsefalsetrueSMALLMEDIUMLARGE动手......
  • java动手动脑-2024.9.28
    枚举类publicclassEnumTest{publicstaticvoidmain(String[]args){Sizes=Size.SMALL;Sizet=Size.LARGE;System.out.println(s==t);System.out.println(s.getClass().isPrimitive());Sizeu=Size.valueOf(&quo......
  • 9月28日记录
    一个管理流水线的MES系统的java实现:代码如下:点击查看代码importjava.util.Scanner;importjava.util.Objects;publicclassPlanInformation{privatestaticintcounter=0;//用于ID递增privateintid;privateStringplanid;privateStringp......
  • 2024-09-28 闲话
    做大模型一年半,经历了无数场面试。经验我最常听到的候选人(尤其是学生)的说辞是:我没有大模型经验,可以给个机会吗?答案是,我们并不看重候选人的大模型训练经验。这里不是说经验不重要,而是大部分人的经验没有意义。只有头部大模型公司的核心骨干的经验才有意义,而这和绝大多数人选无关(e.......
  • 课后练习
    packageshi;importjava.util.Random;publicclassshi{publicstaticvoidmain(String[]args){Randomrandom=newRandom();intnum1,num2,result=0;intoperation;for(inti=0;i<30;i++){//Generaterandomnumbersbet......