Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
来源:互联网 发布:信用卡账单修改软件 编辑:程序博客网 时间:2024/05/16 01:49
题意是给你n个数,要求你从中取k个数,这k个数两两之差可以被m整除。
两个数之差可以被一个数m整除,意味着这两个数%k的值会相同。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 100000;inline int get(){char c;while((c = getchar()) < '0' || c > '9');int cnt = c - '0';while((c = getchar()) >= '0' && c <= '9') cnt = cnt * 10 + c - '0';return cnt;}int N,K,M;int a[MAXN+10];int b[MAXN+10];int cnt[MAXN+10];int main(){#ifdef lwy/*#elsefreopen(".in","r",stdin);freopen(".out","w",stdout);*/#endif scanf("%d %d %d",&N,&K,&M); for(int i = 1; i <= N; i++){ scanf("%d",&a[i]); b[i] = a[i] % M;}for(int i = 1; i <= N; i++){cnt[b[i]]++;}for(int i = 0; i <= M-1; i++){if(cnt[i] >= K){printf("Yes\n");int tot=0;for(int j = 1; j <= N; j++){if(b[j] == i) printf("%d ",a[j]),tot++;if(tot == K) return 0;}}}printf("No");return 0;}
题意是给你一个数n,要你求出是否有一个数,它与它的各个位数之和等于n,如果有多解,则按从小到大顺序输出。
这是题需要审题的题目。
注意到n<=10^9,那么各个位数之和绝对不会大于81,从n-81到n枚举下答案就行了。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 0;inline int get(){char c;while((c = getchar()) < '0' || c > '9');int cnt = c - '0';while((c = getchar()) >= '0' && c <= '9') cnt = cnt * 10 + c - '0';return cnt;}int n;int ans[100],tot=0;int main(){#ifdef lwy/*#elsefreopen(".in","r",stdin);freopen(".out","w",stdout);*/#endifscanf("%d",&n);int t;t = max(n-90,1);for(int i = n; i >= t; i--){int k=i,sum=0;while(k != 0){sum += (k % 10);k /= 10;}sum += i;if(sum == n){tot++;ans[tot] = i;}}printf("%d\n",tot);if(tot > 0){for(int i = tot; i >= 1; i--){printf("%d ",ans[i]);}}return 0;}
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
- He looks through all the coins from left to right;
- If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.
Print n + 1 numbers a0, a1, ..., an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.
41 3 4 2
1 2 3 2 1
86 8 3 4 7 2 1 5
1 2 2 3 4 3 4 5 1
Let's denote as O coin out of circulation, and as X — coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO → OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO → OXOX → OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX → OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
这道题题意比较复杂,给你n个数字,每个数字代表一个位置,总长度为n,每输入一个数字,相当于给这个位置带上了标记,有标记的数字必须移动到没标记的数字后面。每输入一个数字,你都需要输出把所有带标记的位置(包括之前输入的数字)都移动到不带标记数字后所需要操作的步骤数。
操作是这样的。
把这个串从左往右扫描,如果发现位置 i 带标记 而 i+1 不带标记,那么就将这两个位置交换,直到扫描到不需要交换为止。
可以观察出,答案就是等于最后面的不带标记的位置之前的带标记的位置的个数+1
那么直接求解就很好算了。(蒟蒻居然想用链表瞎搞,强行把问题复杂化了..)
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 300000;inline int get(){char c;while((c = getchar()) < '0' || c > '9');int cnt = c - '0';while((c = getchar()) >= '0' && c <= '9') cnt = cnt * 10 + c - '0';return cnt;}int N,P;bool a[MAXN+10];int Now;int main(){#ifdef lwy/*#elsefreopen(".in","r",stdin);freopen(".out","w",stdout);*/#endifmemset(a,false,sizeof(a));scanf("%d",&N);Now = N;printf("1 ");for(int i = 1; i <= N; i ++){int k; scanf("%d",&k);a[k] = true;while(a[Now]) Now --;printf("%d ",1 + i - (N - Now));} return 0;}
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
- Codeforces Round #441 (Div. 1, by Moscow Team Olympiad)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property (2-SAT问题)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) ABCD题解
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins 乱搞
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A-D题解
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins【规律】
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry
- Codeforces Round #441 (Div. 1, by Moscow Team Olympiad) C. National Property CF875C
- 注入指针修改值
- spring中 mvc 的重定向与请求转发
- 1.应用统计与随机过程第二章部分课上例题
- Passwords
- [leetcode] 290. Word Pattern
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)
- Codeforces 876 B Divisiblity of Differences
- 笔试题记录
- 557. Reverse Words in a String III
- hdu1219 AC Me
- 2017年10月17日-ACM涉及知识需掌握
- SpringBoot自定义静态资源映射方法
- swift脚本编程:一键生成AppIcon
- idea intellij main方法 [public static void main(String[] args) 快速生成]