跳到正文

AnBo_Yang

1803286

武侠狂粉前来报到 || BDFZ小蓝 || 是个蒟蒻 || 飞雪连天射白鹿, 笑书神侠倚碧鸳||已退役

在洛谷打开
资料、奖项与版本

资料

编号
1803286
抓取

版本

  1. v2当前
  2. v1

暴力出奇迹,骗分过样例

友情提示一下三个算法的主流写法(以后会添加): //背包

C++
for(int i = 1; i <= n; i++)
	for(int j = 0; j <= m; j++)
	{
		f[i][j] = f[i - 1][j];
  	    if(j >= w[i]) f[i][j] = max(f[i][j], f[i - 1][j - w[i]] + v[i]);
    }
  

//前缀和

C++
for(int i = 1; i <= n; i++)
{
     cin >> a[i];
     s[i] = s[i - 1] + a[i];
}

//二分(函数形式,先不提lower_bound)

我们假设要找的数是x,要查询的数组是a[];

C++
  int l = 1, r = n;
  while(l <= r)
  {
    	int mid = l + (r - l) / 2;
    	if(a[mid] == x) return mid;
    	else if(a[mid] < x) l = mid + 1;
    	else r = mid - 1;
  }
  return -1;

//lower_bound版本

C++
int p = lower_bound(a + 1, a + n + 1, x) - a;
if(a[p] == x) cout << p << endl;
else cout << -1 << endl;

//提供一个高精度算法的大代码,懂得都懂,main函数里自己添。

C++
#include<bits/stdc++.h>
using namespace std;
struct BIG
{
	int len, num[1010];
	void s2BIG(string s)
	{
		len = s.size();
		for(int i = 1; i <= len; i++)
			num[i] = s[len - i] - '0';
	}
	void print()
	{	
		for(int i = len; i >= 1; i--)
			cout << num[i];
	}
	BIG& operator = (const string& s)
	{
		s2BIG(s);
		return *this;
	}
};
BIG operator + (BIG a, BIG b)
{
  BIG c;
  int len = max(a.len, b.len), u = 0;
  for(int i = 1; i <= len; i++)
  {
      int t = u;
      if(i <= a.len) t += a.num[i];
      if(i <= b.len) t += b.num[i];
      c.num[i] = t % 10;
      u = t / 10;
  }
  if(u > 0) c.num[++len] = u;
  c.len = len;
  return c;
}
BIG operator - (BIG a, BIG b)
{
  BIG c;
  int len = max(a.len, b.len), u = 0;
  for(int i = 1; i <= len; i++)
  {
      int t = a.num[i] - u;
      if(i <= b.len) t -= b.num[i];
      if(t < 0)
      {
          u = 1;
          c.num[i] = t + 10;
      }
      else 
      {
          u = 0;
          c.num[i] = t;
      }
  }
  while(c.num[len] == 0 && len > 1) len--;
  c.len = len;
  return c;
}
BIG operator * (BIG a, int b)
{
  BIG c;
  int len = a.len, u = 0;
  for(int i = 1; i <= len; i++)
  {
      int t = a.num[i] * b + u;
      c.num[i] = t % 10;
      u = t / 10;
  }
  while(u > 0)
  {
      c.num[++len] = u % 10;
      u /= 10;
  }
  c.len = len;
  return c;
} 
BIG operator / (BIG a, int b)
{
  BIG c;
  int len = a.len, r = 0;
  for(int i = len; i >= 1; i--)
  {
      int t = r * 10 + a.num[i];
      c.num[i] = t / b;
      r = t % b;
  }
  while(c.num[len] == 0 && len > 1) len --;
  c.len = len;
  return c;
}
int operator % (BIG a, int b)
{
  int len = a.len, r = 0;
  for(int i = len; i >= 1; i--)
  {
      r = r * 10 + a.num[i];
      r %= b;
  }
  return r;
}
bool operator < (BIG a, BIG b)
{
  if(a.len != b.len) return a.len < b.len;
  for(int i = a.len; i >= 1; i--)
      if(a.num[i] != b.num[i])
          return a.num[i] < b.num[i];
  return false;
}
 bool operator == (BIG a, BIG b)
 {
  return !(a < b) && !(b < a);
 }
bool operator != (BIG a, BIG b)
{
    return !(a == b);
}
bool operator > (BIG a, BIG b)
{
    return !(a < b) && (a != b);
}
bool operator >= (BIG a, BIG b)
{
    return (a > b) || a == b;
}
bool operator <= (BIG a, BIG b)
{
    return (a < b) || a == b;
}
BIG operator += (BIG &a, BIG b)
{
    a = a + b;
    return a;
}
BIG operator -= (BIG &a, BIG b)
{
    a = a - b;
    return a;
}
BIG operator *= (BIG &a, int b)
{
    a = a * b;
    return a;
}
BIG operator /= (BIG &a, int b)
{
    a = a / b;
    return a;
}
istream& operator >> (istream& is, BIG& a)
{
    string s;
    is >> s;
    a.s2BIG(s);
    return is;
}
ostream& operator << (ostream& os, BIG& a)
{
    a.print();
    return os;
} 
int main() 
{

    return 0;
}

如有不足之处,欢迎批评指出。 @supercpu @Liang_Px

updateupdate inin :: 2026080420260804

补一个高精×高精的代码:

C++
#include<bits/stdc++.h>
using namespace std;
const int N = 4010;
char s[N];
int lena, lenb, lenc, a[N], b[N], c[N]; 
int main()
{
  cin >> s;
  lena = strlen(s);
  for(int i = 0; i < lena; i++) a[i] =s[lena - 1 - i] - '0';
  cin >> s;
  lenb = strlen(s);
  for(int i = 0; i < lenb; i++) b[i] = s[lenb - 1 - i] - '0';
  for(int i = 0; i < lena; i++)
    for(int j = 0; j < lenb; j++)
      c[i + j] += a[i] * b[j];
  lenc = lena + lenb;
  int u = 0;
  for(int i = 0; i < lenc; i++)
  {
    c[i] += u;
    u = c[i] / 10;
    c[i] %= 10;
  }
  while(u > 0)
  {
    c[++lenc] = u % 10;
    u /= 10;
  }
  for(int i = lenc - 1; i >= 0; i--)
    if(c[i] > 0 || i == 0)
    {
      lenc = i + 1;
      break;
    }
  for(int i = lenc - 1; i >= 0; i--) cout << c[i];
  puts("");
    return 0;
}

我可是最帅气最威武最聪明最强大宇宙无敌超级战神杨大人

新手自恋狂蒟蒻,多多包涵

还没有收录这位用户的文章。