URAL 2065 Different Sums (找规律)

题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k。

析:我们考虑0这个特殊的数字,然后0越多,那么总和种类最少,再就是正负交替,那么增加0的数量。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define frer freopen("in.txt", "r", stdin)
#define frew freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
    while(scanf("%d %d", &n, &m) == 2){
        printf("0");
        if(m & 1){
            for(int i = 1; i <= m/2; ++i){
                printf(" %d %d", i, -i);
            }
            for(int i = 1; i <= n-m; ++i)
                printf(" %d", 0);
        }
        else{
            for(int i = 1; i < m/2; ++i){
                printf(" %d %d", i, -i);
            }
            printf(" %d", m/2);
            for(int i = 1; i <= n-m; ++i)
                printf(" %d", 0);
        }
        printf("\n");

    }
    return 0;
}

  

时间: 2024-08-02 21:33:10

URAL 2065 Different Sums (找规律)的相关文章

【找规律】URAL - 2065 - Different Sums

就让0出现得尽可能多嘛--大概感受一下就是这样-- 0 0 ... 0 0 0 0 4 -4 3 -3 2 -2 1 -1 #include<cstdio> using namespace std; int n,m,a[510]; int main() { scanf("%d%d",&n,&m); int now=0; for(int i=n,j=1;i>=1;--i,++j) { if(m==1) a[i]=0; else { now=-now; i

URAL 2070 Interesting Numbers (找规律)

题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好.打个表,找找规律,你会发现, 这些数除外的数都是素数的素数次方,然后就简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

URAL 1295. Crazy Notions(数学啊 &amp; 找规律)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295 1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of th

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

【55测试】【字符串】【栈】【找规律】

集训第二天,额,考崩了. 第一题 hao 大意:(这个名字就不要在意了,其实是祖玛游戏) 模拟祖玛游戏的模式,给一个'A'~'Z'的字符串,然后有t个插入操作为 “ 添加后的在原字符串的位置 x  插入元素 c ”,字符串中有超过或等于 3 个相同的字符,则被消除,输出每次操作后剩余的字符串,如果为空,则输出“-”. 样例: ACCBA                     输出:  ABCCBA 5   AABCCBA 1 B AABBCCBA 0 A - 2 B A 4 C 0 A 解:

2016(胡赛复现)_大数找规律

Time Limit: 5 Sec  Memory Limit: 128 MB Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m;  2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤109). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000

HDU 5703 Desert 水题 找规律

已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

找规律/hdu 1005 Number Sequence

题意 给出a,b,n,已知f[1]=f[2]=1,f[i]=(a*f[i-1]+b*f[i-2]) mod 7 输出f[n] 数据范围 1 <= A, B <= 1000, 1 <= n <= 100,000,000 分析 首先,直接求..肯定是不行的 会tle 会mle 但是可以找到规律,例如对a=1,b=1 这个数据,有 f1=1 f2=1 f3=3 f4=5 f5=4 f6=0 f7=1 f8=1 f9=3 f10=5 f11=4 f12=0 ???? 我们会发现有一定的规律