USACO section1.1:
DONE 2017.03.03 TEXT Submitting Solutions
DONE 2017.03.04 PROB Your Ride Is Here [ANALYSIS]
DONE 2017.03.04 TEXT Contest Problem Types
DONE 2017.03.04 TEXT Ad Hoc Problems
DONE 2017.03.04 PROB Greedy Gift Givers [ANALYSIS]
DONE 2017.03.04 PROB Friday the Thirteenth [ANALYSIS]
DONE 2017.03.04 PROB Broken Necklace [ANALYSIS]
由上可见section1.1中共有四道题,没有考察算法,只是单纯看思考是否到位以及细心程度。

Prob1:Your Ride Is Here(水题)
题意:input给出两个全部由大写字母组成的单词, 每个字母对应一个数字(A-1,B-2……),
两个单词中的字母分别相乘,得到两个数字, 判断这两个数字%47的余数是否相等。

NOTE:由于数据很小,无须担心溢出,但是保险起见,还是在每次运算的过程中取余。(a%b)*(c%b) = (a*c)%b;

源代码:

 /*
ID:kongse_1
PROG:ride
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MOD = ;
string a, b;
int num1= ,num2=;
int main()

 freopen("ride.in", "r", stdin);
 freopen("ride.out", "w", stdout);
 cin >> a >> b;
 
 for(int i = ; i != a.size(); ++i)
  num1 = (num1*(a[i]-'A'+))%MOD;
 for(int i = ; i != b.size(); ++i)
  num2 = (num2*(b[i]-'A'+))%MOD;
 
 if(num1 == num2) cout << "GO" << endl;
 else cout << "STAY" << endl;
 fclose(stdin);
 fclose(stdout);
 return ;
}

Prob2:Greedy Gift Givers (水题)
题意:有n个人,没人开始身上有0块钱,每个人选择掏出x的钱给他指定的n个人买礼物,他指定的人每个人得到x/n块钱,若除不尽(x%n)则多出来的零钱归他自己。输出一轮之后每个人对应的钱数(可以是负的...)。

P.S:本来开始想要用map做一一映射,结果map自带排序,把原来输入的顺序搞没了,于是乎只能拿俩数组维护。

源代码:

 /*
ID:kongse_1
PROG:gift1
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = ;
string x[maxn], y[maxn], z;
int num, sum, n, money[maxn];
int find_(string curr)
{
 for(int i = ; i != num; ++i)
 {
  if(x[i] == curr) return i;
 }
}
void calculate_(int a, int b)
{
 money[a] -= b;
 return ;
}
int main(){
 freopen("gift1.in", "r", stdin);
 freopen("gift1.out", "w", stdout);
 
 cin >> num;
 
 for(int i = ; i != num; ++i)
 {
  cin >> x[i];
 }
 
 for(int i = ; i != num; ++i)
 {
  cin >> z >> sum >> n; 
  if(n)
  {
   calculate_(find_(z), sum-sum%n);
   for(int j = ; j != n; ++j)
   {
    cin >> y[j];
    calculate_(find_(y[j]), -sum/n);
   } 
  }
 }
 
 for(int i = ; i != num; ++i)
 {
  cout << x[i] << " " << money[i] << endl;
 }
 fclose(stdin);
 fclose(stdout);
 return ;
}

Prob3:Friday the Thirteenth
题意:已知1900年1月1日是周一,统计包括1900年在内的N年间,每月13号是周一——周日的次数。

NOTE1:得到1900年1月13日是周六,根据每个月的天数算出下一个月13日是星期几,注意判断闰年即可。

NOTE2:如果按照每年作为单位一步步求,会出现一个问题:每一年算的第12次实际上算的是下一年的1月13日(+31即是度过了12月份到了一月),所以算的最后一年的循环要特判。
源代码:

 /*
ID:kongse_1
PROG:friday
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
int month[maxn]={,,,,,,,,,,,,}, N, times[maxn], curr = ;
int whether(int year)
{
 if(year% == || (year% == && year% != )) return ;
 return ;
}
void caculate_(int year)
{
 if(year == +N) return ;
 
 if(whether(year)) month[] = ;
 else month[] = ;
 
 for(int i = ; i != ; ++i)
 {
  curr = (curr+month[i])%;
  if(i == && year == +N-) break;
  ++times[curr];
 }
 caculate_(year+);
}
int main()
{
 freopen("friday.in", "r", stdin);
 freopen("friday.out", "w", stdout);
 
 cin >> N;
 
 ++times[];
 caculate_();
 
 cout << times[] << " ";
 for(int i = ; i != ; ++i)
 {
  cout << times[i];
  if(i != ) cout << " ";
 }
 cout << endl;
 
 fclose(stdin);
 fclose(stdout);
 return ;

Prob4:Broken Necklace(有点意思)
题意:一串项链有三种颜色:红(r),蓝(b),白(w)。从中间某一处断开,从断开的两边分别去从头取颜色相同的珠子(两边右的可摘取数,然后从两个序列中找到a[i]+b[i+1]最大值(因为是从中间断的两川,所以一定是相邻的且向左的是第i个,向右的是第(i+1)%n)个。(注意,这是一串项链,首尾相连,是个循环队列)。

而算出没一个的向左区和向右取的值也很简单,不需要每个都算,例如算出第i个可以向左取m个,那么第(i-1)个,即他的左边一定只能取(m-1)个(m!=1),m = 1即只有自己。当出现左边的颜色与当前颜色不同时再重新计算。但是有一个例外。

我们观察这样的一串:bbwbwrrwrwr 第一个b是5,第五个w则应该是1,但是事实上第五个应该是7,因为它跟右边的红色也可以相连。所以我们得到特判:当上一个是2并且当前是白色(w)时应重新计算(即w是某队队尾)。

源代码:

 /*
ID:kongse_1
PROG:beads
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int maxn = ;
string x;
int n, num[][maxn], max_;
int whether(char a, char b)
{
 if(a+b == 'r'+'b') return ;
 return ;
}
void calculate_(int curr, string y)
{
 char last = x[curr];
 if(y == "left")
 {
  int wh = ;
  num[wh][curr] = ;
  for(int i = (curr-+n)%n;i != curr ; i = (i-+n)%n)
  {
   if(x[i] == last || x[i] == 'w' || last == 'w')
   {
    if(last == 'w') last = x[i];
    ++num[wh][curr];
   }
   else break;  
  }
 }
 
 else
 {
  int wh = ;
  num[wh][curr] = ;
  for(int i = (curr+)%n; i != curr ; i = (i++n)%n)
  {
   if(x[i] == last || x[i] == 'w' || last == 'w')
   {
    if(last == 'w') last = x[i];
    ++num[wh][curr];
   }
   else break;
  }
 }
 return ;
}
int main()
{
 freopen("beads.in", "r", stdin);
 freopen("beads.out", "w", stdout);
 
 cin >> n >> x; 
 
 for(int i = ; i != n; ++i)
 {
  if( !i || (num[][(i-+n)%n] == && x[i] == 'w') || whether(x[(i-+n)%n],x[i]) )
   calculate_(i, "right");
   else num[][i] = num[][i-]-;
 }
 
 for(int i = n-; i != -; --i)
 {
  if( i == n- || (num[][(i+)%n] == && x[i] == 'w') || whether(x[(i+)%n],x[i]) )
   calculate_(i, "left");
  else num[][i] = num[][i+]-;
 }
 
 for(int i = ; i != n; ++i){
 
  max_ = max(max_, num[][i]+num[][(i-+n)%n] ); 
 }
 
 cout <<((max_<n)?max_:n) << endl;
 
 fclose(stdin);
 fclose(stdout);
  
 return ;
}

自此,USACO section1.1便全部完成了。
箜瑟_qi 2016.03.04

USACO section 1.1 C++题解的更多相关文章

  1. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  2. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  3. bzoj usaco 金组水题题解(1)

    UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT. ...

  4. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  5. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  6. USACO Section 5.3 Big Barn(dp)

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  7. USACO Section 1.3 Wormholes 解题报告

    题目 题目描述 在一个二维平面上有N个点,这N个点是(N/2)个虫洞的端点,虫洞的特点就是,你以什么状态从某个端点进去,就一定会以什么状态从另一端的端点出来.现在有一头牛总是沿着与X轴正方向平行的直线 ...

  8. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  9. USACO Section 1.1 Your Ride Is Here 解题报告

    题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...

随机推荐

  1. php文件管理与基础功能的实现

    文件的基本操作 先来看一下PHP文件基础操作,请看强大注释 <body> <?php var_dump(filetype("./img/11.png")); // ...

  2. 【转】SQL Server海量数据库的索引、查询优化及分页算法

    探讨如何在有着1000万条数据的MS SQL SERVER数据库中实现快速的数据提取和数据分页.以下代码说明了我们实例中数据库的“红头文件”一表的部分数据结构: CREATE TABLE [dbo]. ...

  3. CSS常见兼容性问题总结

    原文链接:渔人码头 http://www.cnblogs.com/imwtr/p/4340010.html?utm_source=tuicool&utm_medium=referral 浏览器 ...

  4. shell脚本监控目录下文件被篡改时报警

    思路: 目录下文件被篡改的几种可能: 1.被修改 2.被删除 3.新增文件 md5命令详解 参数: -b 以二进制模式读入文件内容 -t 以文本模式读入文件内容 -c 根据已生成的md5值,对现存文件 ...

  5. JvisualVM、JMC监控远程服务器

    修改服务器上jmxremote.access与jmxremote.password,输入命令: find -name jmxremote.access进入该jmxremote.access文件所在目录 ...

  6. 任务调度之集群(基于Quartz.net)

    上一篇我们完成了任务调度的持久化,传送门:任务调度之持久化(基于Quartz.net) 这篇我们来完成Quartz.net的一个比较优秀的功能,即集群:集群可以提高任务调度服务的容灾性, 当一个节点宕 ...

  7. 关于SQL调优(Distinct 和 Exits)

    今天写了一段查询人员Id和人员编号的,由于需要从其他的表中取条件,因为人员表和另外的表对应的是一对多的关系,所以我使用了Distinct关键字对用户编号进行去重复,然后发现那个效率简直没法看,然后旁边 ...

  8. 关于SQL的一些小知识

    在代码中调用存储过程的时,必须先测试存储过程,存储过程测试成功之后再去java中去调用!!@!@#!@!@! 以后自己写的存储过程写一个本地保存一个.!~~~!!(这个很关键) 以后在代码中的SQL都 ...

  9. 给自己的 MAC 添加一个桌面日历

    使用 Ubuntu 做自己的办公环境用了将近三年,最近换了新款的 MBP,系统都用的很舒服. 不过 Ubuntu 是在我的 TP W540上部署的,而 W540 + 电源适配太重了(我的电池是9芯的) ...

  10. ORA-00918: 未明确定义列

    ORA-00918: 未明确定义列 出现问题原因及解决办法. --正常写,结果带上表名的字段在处理后表头名称相同,在进行下一次嵌套时就会出现问题  select au.userxm,au01.user ...