Codeforces Intel Code Challenge Final Round (Oct/08/2016)

A
大意就是判断会不会在一个平年中出现相邻的两个月的第一天分别是给定的日期。

判断一下 31 mod 7 , 30 mod 7 , 28 mod 7 就好。

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

char ch[100];
int x, y;

int main(void) {
    freopen("1.in", "r", stdin);
    gets(ch);
    if (ch[0] == 'm') x = 1;
    else if (ch[0] == 't' && ch[1] == 'u') x = 2;
    else if (ch[0] == 'w') x = 3;
    else if (ch[0] == 't') x = 4;
    else if (ch[0] == 'f') x = 5;
    else if (ch[0] == 's' && ch[1] == 'a') x = 6;
    else x = 7;
    gets(ch);
    if (ch[0] == 'm') y = 1;
    else if (ch[0] == 't' && ch[1] == 'u') y = 2;
    else if (ch[0] == 'w') y = 3;
    else if (ch[0] == 't') y = 4;
    else if (ch[0] == 'f') y = 5;
    else if (ch[0] == 's' && ch[1] == 'a') y = 6;
    else y = 7;
    y -= x; y = (y + 7) % 7;
    if (y == 0 || y == 2 || y == 3) puts("YES");
    else puts("NO");
} 

B

You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n+1 actions in total. Operations can be performed in any order.

既然最后可以交换两列,那么对于一个排序号的排列枚举交换的位置,一一匹配即可

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int mp[30][30], a[30][30], b[30];
int n, m, cnt;
bool flag = 0;

int main(void) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", &mp[i][j]);
    for (int i = 1; i <= m; i++) b[i] = i;
    for (int i = 1; i <= n; i++) {
        cnt = 0;
        for (int j = 1; j <= m; j++)
            cnt += (mp[i][j] != b[j]);
        if (cnt > 2) goto w;
    }
    flag = 1; w:;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= m; j++) {
            swap(b[i], b[j]);
            for (int k = 1; k <= n; k++) {
                cnt = 0;
                for (int x = 1; x <= m; x++)
                    cnt += (mp[k][x] != b[x]);
                if (cnt > 2) goto W;
            }
            flag = 1;
            W:swap(b[i], b[j]);
        }
    if (flag) puts("YES");
    else puts("NO");
    return 0;
}

C
给定 nm 的网格,从 (0,0) 有一道射线以 v=2 射出,遇到墙壁反射遵守反射定律。求射线经过 (x,y) 的时间。

可以把这张网格图拓展成 (lcm(n,m),lcm(n,m)) ,然后发现其实总共四种情况 (x,y) (2nx,y) (x,2my) (2nx,2my)
只要预处理出每过 m <script type="math/tex" id="MathJax-Element-21">m</script>时间的位置即可。其实就是在普通的计算过程中取模。

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

inline char get(void) {
    static char buf[100000], *p1 = buf, *p2 = buf;
    if (p1 == p2) {
        p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
        if (p1 == p2) return EOF;
    }
    return *p1++;
}
template<typename T>
inline int read(T &x) {
    static char c; x = 0;
    for (c = get(); c < '0' || c > '9'; c = get());
    for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = get());
    return x;
}
template<typename T>
inline T Min(T a, T b) {
    return a < b ? a : b;
}

const ll N = 100100, INF = 1e16;

ll n, m, k, x, y, pos, Cnt, res;
ll cnt[N << 2];

ll Calculate(ll x, ll y) {
    ll p = ((y - x) % n + n) % n;
    if (cnt[p] == -1) return INF;
    return m * cnt[p] + x;
}

int main(void) {
    read(m); read(n); read(k);
    n <<= 1; m <<= 1;
    memset(cnt, -1, sizeof cnt);
    while (1) {
        if (cnt[pos] != -1) break;
        cnt[pos] = Cnt++;
        pos = (pos + m) % n;
    }
    for (int i = 0; i < k; i++) {
        read(x); read(y); res = INF;
        res = Min(res, Calculate(x, y));
        res = Min(res, Calculate(m - x, y));
        res = Min(res, Calculate(x, n - y));
        res = Min(res, Calculate(m - x, n - y));
        if (res == INF) res = -1;
        printf("%I64d\n", res);
    }
    return 0;
}
Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值