Integer Game(UVA11489)3的倍数
K - Integer Game
Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
题意:在n中取数字,使剩下的数是3的倍数,不能取则失败。
思路:如果能使当前数为3的倍数,数字和必是3的倍数。要保持这种状态,先对每一位对3取余,统计cnt[0],cnt[1],cnt[2]; 的个数,整个串能否被3整除取决于ans=(cnt[1]+cnt[2]*2)%3;分情况讨论,如果能整除,则,判断cnt[0]的个数,如果是偶数个则T,否则S;如果不能整除,则,要特判cnt[ans]的个数是否大于0;<eg:11111>;大于0,则cnt[0]的个数为偶数个则S,否则T;等于0则T;
一直坑在11111这种情况!o(︶︿︶)o 唉
转载请注明出处:寻找&星空の孩子
#include<stdio.h>
#include<string.h>
int main()
{
int T,len,ca=;
scanf("%d",&T);
char a[]; while(ca<=T)
{
scanf("%s",a);
len=strlen(a);
int cnt[]={,,};
for(int i=;i<len;i++)
{
int tp=a[i]-'';
cnt[tp%]++;
}
printf("Case %d: ",ca++);
int mo=(cnt[]+cnt[]*)%;
if(mo)
{
if(cnt[mo]>)//
{
if(cnt[]&) printf("T\n");
else printf("S\n");
}
else
{
printf("T\n");
}
}
else
{
if(cnt[]&) printf("S\n");
else printf("T\n");
}
}
return ;
}
Integer Game(UVA11489)3的倍数的更多相关文章
- K - Large Division 判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余;
/** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数. a (-10^200 ≤ ...
- uva11489 - Integer Game(考思维,找规律)
从S开始时只能是两种情况: 1.现在总和已经是3的倍数了,那么因为每人每次只能拿走一个数,要保持拿走之后依然是3的倍数,那么就只能拿3,6,9这类数,用num统计一下,看看num奇偶性就知道谁最后拿了 ...
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- Leetcode Integer Replacement
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- LA 4119 (差分数列 多项式) Always an integer
题意: 给出一个形如(P)/D的多项式,其中P是n的整系数多项式,D为整数. 问是否对于所有的正整数n,该多项式的值都是整数. 分析: 可以用数学归纳法证明,若P(n)是k次多项式,则P(n+1) - ...
- Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
- Roman to Integer && Integer to Roman 解答
Roman Numeral Chart V:5 X:10 L:50 C:100 D:500 M:1000 规则: 1. 重复次数表示该数的倍数2. 右加左减:较大的罗马数字右边记上较小的罗马数字,表示 ...
- leetcode第七题--Reverse Integer
Problem: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 ...
- [LeetCode] Reordered Power of 2 重新排序为2的倍数
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
随机推荐
- tomcat服务器怎样远程调试
适合windows系统 1.首先tomcat/bin目录下startup.bat打开最前面添加以下代码: SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Dj ...
- flask上下文详解
一.前言 了解过flask的python开发者想必都知道flask中核心机制莫过于上下文管理,当然学习flask如果不了解其中的处理流程,可能在很多问题上不能得到解决,当然我在写本篇文章之前也看到了很 ...
- javascript之location详解
window.location.hash 使用说明 今天给大家详细汇总了关于window.location.hash的知识点,属性以及用法等等,非常的实用,并附上了例子,有需要的小伙伴可以参考下. l ...
- idea中如何将单个java类导出为jar包文件?
idea作为一个java开发的便利IDE工具,个人是比较喜欢的,今天来探索个小功能: 导出单个类文件为jar包! 偶有这种需求,就是某个类文件独立存在,但是需要将其导出为jar,供别人临时使用,或者 ...
- Testing - 敏捷测试
敏捷测试(Agile Testing) SM= Scrum Master PO= Product Owner PB= Product Backlog SB= Sprint Backlog Scrum ...
- 【PHP篇】面向对象基础
1.声明:class 类名{ //成员属性(变量) 修饰符 $变量名=初值: //成员方法(函数) 修饰符 function 函数名(){ 执行:} } 2.生成类对象:$对象名=new 类名():/ ...
- preg_replace的一些细节
.$pattern是数组,$replace也是数组,则中对应的 元素进行替换 php preg_replace有五个参数,有三个是必须参数 Preg_replace(mixed $pattern, m ...
- MySql数据库安装
MySql数据库安装 一丶数据库 什么是数据库 数据库简单连接就是存储数据的容器. 而库则是一组容器合成的东西. 也就是存储数据的.我们编程中常常会用到数据库. 什么是数据管理系统 数据库管理系统就是 ...
- 【原创】USART异步模式配置
特性: (1)USART只能一位一位地发送和接受数据,在起始位期间,TX端处于低电平:当闲置时,TX端为高. (2)发送和接受由一共用的波特率发生器驱动,当发送器和接收器的使能位分别置位时,分 ...
- 基于vue技术的企业移动办公系统的设计与实现
如何打包: http://www.cnblogs.com/smilehuanxiao/p/7693858.html http://www.cnblogs.com/1314y/p/6207153.htm ...