srm 617 div2

1:求两个和数x,y,使得x+y = n。刚开始没看懂题目意思就开始敲。。。结果可想而知。再次细心读题才发现。果然要做题必须要先理解题意。(才得了207.52)

bool is_prime(int x){
  if(x == 2) return true;
  for(int i = 2; i <= sqrt(x); i ++)
    if(x % i == 0) return false;
  return true;
}

class SilverbachConjecture{
  public :
  vector <int> solve(int n){
    vector<int> a;
    int x, y;
    for(int i = 2; i <= n; i ++){
      x = i;
      y = n - i;
      if(!is_prime(x) && !is_prime(y) )
        break;
    }
    a.push_back(x);
    a.push_back(y);
    return a;
  }
};

2:简单模拟题。题目大意:第i天可以产morning[i]个东东,第i天可以卖customers[i]东东,如果customer[i] < morning[i]那么只能卖customers[i]个东东,余下的第二天来卖但是第stale_limit天前的东东会腐烂,所以要扔掉,不能卖。

(翻译有点不好,但是意思就是这样O(∩_∩)O哈哈~)(~~~~(>_<)~~~~ ,这题才的247.94。还以为可以涨为绿呢)

 

class SlimeXSlimonadeTycoon{
  public :
  int sell(vector <int> morning, vector <int> customers, int stale_limit){
      int n = morning.size();
      int sum = 0;
      for(int i = 0; i < n; i ++){
        int s = i-stale_limit+1 >= 0 ? i-stale_limit+1 : 0;
        //cout << s << endl;
        for(int j = s; j <= i; j ++){
          int temp =  customers[i] > morning[j] ? morning[j] : customers[i];
          customers[i] -= temp;
          morning[j] = morning[j] - temp;
          sum += temp;
        }
      }
      //cout << sum << endl;
      return sum;
  }
};

感觉要上一个台阶,真的好难咦,不过努力吧,突破这个瓶颈,向更高方向前进。。好好打基础。。

3:先暴力枚举要切的点,然后统计一下就行了。但是这样对于10^9的数据暴力的话绝壁超时。然后你会发现这些数刚好是n-phi(n);想到这点后就容易解决了。



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值