CodeForces Div2 433

A题 Fraction

暴力枚举 无思维难度 无坑点

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 int n,Mi,Mj;
 5 double Max,now;
 6 int main(){
 7     scanf("%d",&n);
 8     for(int i=1;i<n;i++){
 9         for(int j=1;j<i;j++){
10             //printf("%d %d gcd:%d\n",i,j,__gcd(i,j));
11             if(i+j==n && __gcd(i,j)==1){
12                 double x=i;
13                 double y=j;
14                 now = y/x;
15                 //printf("%.2f\n",now);
16                 if(now>Max){
17                     Max = now;
18                     Mi = i;
19                     Mj = j;
20                 }
21             }
22         }
23     }
24     printf("%d %d\n",Mj,Mi);
25     return 0;
26 }

T1

B题 Maxim Buys an Apartment

手写几组数据就能发现这是一个结论题目,特判一下特殊情况就OK了。

 1 #include <cstdio>
 2 #include <iostream>
 3 typedef long long ll;
 4 ll n,k;
 5 int main(){
 6     std::cin>>n>>k;
 7     if(n==1){
 8         printf("0 0");
 9         return 0;
10     }
11     if(n==k){
12         printf("0 0");
13         return 0;
14     }
15     if(k==0){
16         printf("0 0");
17         return 0;
18     }
19     printf("1 ");
20     if(2*k<=n-k){
21         std::cout<<2*k;
22     }
23     else std::cout<<n-k;
24     return 0;
25 }

T2

C题 Planning

比赛时始终没有想到这个算法怎么实现。。。赛后看了下题解,发现还是自己too young
贪心思路:每一秒走能走的最贵的飞机

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 struct p
 5 {
 6     ll x,y;
 7     p(ll x=0,ll y=0):x(x),y(y){}
 8     bool operator <(const p&t)const
 9     {
10         if (x==t.x) return y<t.y;
11         return x>t.x;
12     }
13 };
14 p a[300005];
15 p b[300005];
16 int num[300005];
17 bool use[300005];
18 int main()
19 {
20     ios::sync_with_stdio(false);
21     ll n,k;
22     cin>>n>>k;
23     for(int i=1;i<=n;i++)
24     {
25         cin>>a[i].x;
26         a[i].y=i;
27     }
28 //排序
29     sort(a+1,a+1+n);
30     ll ans=0;
31     int now=1;
32     memset(use,0,sizeof(use));
33     for(int i=1;i<=n;i++)
34         if (!use[i])
35     {
36 //如果当前有和y一样的次序 就不用加和
37         while(a[now].y>i+k)
38         {
39                 num[a[now].y]=a[now].y;
40                 use[a[now].y-k]=1;
41                 now++;
42         }
43 //对于当前比较大的 我尽量让差值尽量下就行了,因为i+k是递增的,所以当前值一定是最优的
44         if (i+k>=a[now].y)
45         {
46             num[a[now].y]=i+k;
47             ans+=a[now].x*(i+k-a[now].y);
48             use[i]=1;
49             now++;
50         }
51     }
52     cout<<ans<<endl;
53     for(int i=1;i<n;i++)
54         cout<<num[i]<<" ";
55     cout<<num[n]<<endl;
56     return 0;
57 }

T3

D题 Jury Meeting

待补

E题

思路:容斥原理+可持久化线段树

可持久化线段树不会写Orz 继续留坑

时间: 2024-10-09 15:29:22

CodeForces Div2 433的相关文章

Codeforces Round #433 (Div. 1) D. Michael and Charging Stations(dp)

题目链接:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations 题意: 一个人每天要加油,1种为1000,1种为2000,如果付全额,会得到10%的回扣放在卡上. 如果卡上有剩余的回扣,可以拿来抵现金.问n天最少需要花多少钱. 题解: 很直观的一个dp就是考虑dp[i][j],表示第i天卡上剩余回扣为j的最小花费. 将所有的数除以100后,j其实是小于40的,严格的说是小于30,官方题解有个证明. 因为卡上不可能积累很多的

Codeforces Round #433 (Div. 2)

题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int gcd(int a,int b){re

codeforces round #433 div2

A:枚举一下就行了...居然wa了一发,题目一定要看清 #include<bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int mid = n / 2 - ((n & 1) == 0); for(int i = n / 2; i; --i) { if(__gcd(i, n - i) == 1) { printf("%d %d\n", i, n - i); return

Codeforces Round #433

A.Fraction 思路:暴力 AC代码: #include "iostream" #include "iomanip" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively num

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction

题意:2个数A,B,A+B==n,并且A<B,问最大的A/B是多少,A与B互质 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 int n; 9 cin>>n; 10 for(int i=n/2;i>=1;i--){ 11 int y=n-i; 12 if(__gcd(i,y)==1){

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning

题意:给出每个航班花费和顺序,求新顺序使得花费最少 思路:肯定是花费最大的先决定,二分一下 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 struct node{ 7 ll x; 8 int id; 9 ll yy; 10 }a[300004]; 11 bool cmp(node p,node q){ 12 return p.x>q.x

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B. Maxim Buys an Apartment

题意:有n个房子,k个有人住,问最少有多个,最多有多少个好的房子,好的房子定义:周围最少有一个房子有人住 思路:我们可以知道一个住了人的房子他最多产生2个好的房子(左右)所以判断k*3是否>=n 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 ll n,k; 9 cin>>n>>k;

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator