Codeforces Round #268 (Div. 2)

补题解:

E:只会第四种解法;也只看懂了这一种。

PS:F[X+10^18]=F[X]+1;F[X]表示X的数字之和;

假设X,F[10^18+X]+F[10^18+X-1]+......F[10^18+1]=F[1]+.....+F[X]+X;

这个应该没问题所以有G[10^18+X]-G[10^18]=G[X]+X;

G[X]表示:1-X的数字和的总和;

根据G[10^X]=45*X*10^(X-1);所以G[10^18]=45*18*10^17;

所以G[10^18+X]-G[X]=(G[10^18]+X)%a;

然后就可以推出时X的大小,X=a-G[10^18]%a;

这样这题就完美解决;

 1 #include <stdio.h>
 2 #include<iostream>
 3 void solve(){
 4     unsigned long long  s = 100000000000000000ll;
 5     __int64 p = s * 10;
 6     __int64 a;
 7     scanf("%I64d",&a);
 8     s = (s * 45) % a;
 9     s = (s * 18 + 1) % a;
10     a = a - s;
11     printf("%I64d %I64d\n",1 + a,p + a);
12 }
13 int main(){
14     solve();
15     return 0;
16 }

D题:@狗哥有个好想法;

假如B>A;

那么对于一个数组最小的数X,如果能在B-X=PB找到他的匹配,那么不用再A中找到,

原因是假如X“嫁"给了A,在A中会有一个A-X=YA与之搭配。

但是PB就找不到”老婆“了,因为A-X<B-X,但是X已经是最小的,所以PB就无法对应了,

然后就是写法的问题了;

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<map>
 8 #include<string>
 9 typedef long long ll;
10 using namespace std;
11 int ans[123456];
12 map<int,int>mp;
13
14 int n,a,b;
15 int pa,pb;
16
17 int main()
18 {
19     cin>>n>>a>>b;
20     for (int i=1;i<=n;i++)
21     {
22         int x;
23         cin>>x;
24         mp[x]=i;
25     }
26     int pa=1,pb=2;
27     if (a>b) swap(a,b),swap(pa,pb);
28
29     for (map<int,int>::iterator mi=mp.begin();mi!=mp.end();mi++)
30     {
31         int val=mi->first;
32         int pos=mi->second;
33         if (ans[pos]) continue;
34         if (mp.find(b-val)!=mp.end()&&ans[mp[b-val]]!=pa)
35             ans[pos]=ans[mp[b-val]]=pb;
36         else if (mp.find(a-val)!=mp.end()&&ans[mp[a-val]]!=pb)
37             ans[pos]=ans[mp[a-val]]=pa;
38         else
39         {
40             cout<<"NO"<<endl;
41             return 0;
42         }
43     }
44     cout<<"YES"<<endl;
45     for (int i=1;i<=n;i++) cout<<ans[i]-1<<" ";
46     return 0;
47 }

C:我分奇数偶数;

因为1*2*3*4=24;

6-5=1;

8-7=1;

10-9=1;

发现了什么,

奇数也可以类推;

1,2,3,4,5手动找一下;

7-6=1;

9-8=1;

然后就可以了

B,A基本照着模拟就可以了

时间: 2024-08-21 12:39:53

Codeforces Round #268 (Div. 2)的相关文章

Codeforces Round #268 (Div. 2) (被屠记)

c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题...开个数组即可.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorith

Codeforces Round #268 (Div. 1) solution

A.24 Game 题意:给你1, 2, ..., n-1, n 这个序列,每次你可以取出两个数做+/-/*三种操作之一,然后把结果放回到序列中,询问能否是的这个序列最后只剩下一个24. 解法:首先很明显n < 4的时候是无解的.如果n=4,那么1 * 2 * 3 * 4=24,如果n=5,那么(5 - 1 - 2) * 3 * 4 = 24.若n > 5,那么我可以做n - (n - 1) = 1,相当于变成了n-2时候的情况加一个1,那么显然最后让答案乘上这个1即可. 代码: includ

Codeforces Round #268 (Div. 2) 题解

A. I Wanna Be the Guy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted

Codeforces Round #268 (Div. 1) 题解

A:24 Game 题意:给一个n,求从1到n通过加减乘除得到24的方法. 题解:不难想到n<4时候肯定是无解的, n=4时候 1+2=3 3+3=6 6*4=24 n=5时候1*5=5 5-2=3 3+3=6 6*4=24 当n>5时候我们可以让n-(n-1)=1 1*1=1 这样就把1~n变成了1~n-2 所以对于任意给定的n,我们把(5~n)这段的数相邻的相减变成1最终转换成用1~4或者1~5构造答案即可. 1 #include <cstdio> 2 3 #include &

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd