Sudoku Checker

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each column, each row, and all 9 non-overlapping 3x3 sub-matrices contain all of the digits from 1 through 9. Each 9x9 matrix is partially completed at the start of game play and typically has a unique solution.

      

Given a completed N2×N2 Sudoku matrix, your task is to determine whether it is a valid solution.

A valid solution must satisfy the following criteria:

  • Each row contains each number from 1 to N2, once each.
  • Each column contains each number from 1 to N2, once each.
  • Divide the N2×N2 matrix into N2 non-overlapping N×N sub-matrices. Each sub-matrix contains each number from 1 to N2, once each.

You don't need to worry about the uniqueness of the problem. Just check if the given matrix is a valid solution.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow. Each test case starts with an integer N(3 ≤ N ≤ 6).

The next N2 lines describe a completed Sudoku solution, with each line contains exactly N2 integers.

All input integers are positive and less than 1000.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is "Yes" (quotes for clarity only) if it is a valid solution, or "No" (quotes for clarity only) if it is invalid.

Sample Input

3
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 999 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9

Sample Output

Case #1: Yes
Case #2: No
Case #3: No
应用时:8min
实际用时:12min
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int bull[50][50];
int col[50][50];
int row[50][50];
int calc(int i,int j){
int ans=(i/n)*n+j/n;
return ans;
}
int main(){
int T;
scanf("%d",&T);
for(int ti=1;ti<=T;ti++){
scanf("%d",&n);
bool fl=false;
memset(bull,0,sizeof(bull));
memset(col,0,sizeof(col));
memset(row,0,sizeof(row));
for(int i=0;i<n*n;i++){
for(int j=0;j<n*n;j++){
int tmp;
scanf("%d",&tmp);
if(tmp<1||tmp>n*n){
fl=true;
continue;
}
if(row[i][tmp]){
fl=true;
}
else row[i][tmp]=true;
if(col[j][tmp]){
fl=true;
}
else col[j][tmp]=true;
int bullnum=calc(i,j);
if(bull[bullnum][tmp]){
fl=true;
}
else {
bull[bullnum][tmp]=true;
}
}
}
if(!fl)printf("Case #%d: Yes\n",ti);
else printf("Case #%d: No\n",ti);
}
return 0;
}

  B:

Read Phone Number

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Do you know how to read the phone numbers in English? Now let me tell you.

For example, In China, the phone numbers are 11 digits, like: 15012233444. Someone divides the numbers into 3-4-4 format, i.e. 150 1223 3444. While someone divides the numbers into 3-3-5 format, i.e. 150 122 33444. Different formats lead to different ways to read these numbers:

150 1223 3444 reads one five zero one double two three three triple four.

150 122 33444 reads one five zero one double two double three triple four.

Here comes the problem:

Given a list of phone numbers and the dividing formats, output the right ways to read these numbers.

Rules:

Single numbers just read them separately.

2 successive numbers use double.

3 successive numbers use triple.

4 successive numbers use quadruple.

5 successive numbers use quintuple.

6 successive numbers use sextuple.

7 successive numbers use septuple.

8 successive numbers use octuple.

9 successive numbers use nonuple.

10 successive numbers use decuple.

More than 10 successive numbers read them all separately.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow. Each line contains a phone number N(1 ≤ length of N ≤ 100) and the dividing format F, one or more positive integers separated by dashes (-), without leading zeros and whose sum always equals the number of digits in the phone number.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the reading sentence in English whose words are separated by a space.

Sample Input

3
15012233444 3-4-4
15012233444 3-3-5
12223 2-3

Sample Output

Case #1: one five zero one double two three three triple four
Case #2: one five zero one double two double three triple four
Case #3: one two double two three 应用时:10min
实际用时:48min
WWWA
原因1:没有弄清base是在前的
2:s在应该稳定的过程中变化
3:读取整数失误导致只能读取1位数字
#include <string>
#include <iostream>
using namespace std;
string base[11]={
""," double"," triple"," quadruple"," quintuple"," sextuple",
" septuple"," octuple"," nonuple"," decuple",
};
string num[10]={
" zero"," one"," two"," three"," four"," five"," six"," seven"," eight"," nine",
};
int read(string str,int &i){
int ans=0;
while(i<str.size()&&(str[i]>'9'||str[i]<'0'))i++;
for(;i<str.size()&&str[i]<='9'&&str[i]>='0';i++){
ans=ans*10+str[i]-'0';
}
return ans;
}
void change(string &ans){
for(int i=0;i<ans.size();i++){
if(ans[i]==' ')ans[i]='_';
}
}
int main(){
ios::sync_with_stdio(false);
int T;
cin>>T;
for(int ti=1;ti<=T;ti++){
string ans="",aim,format;
cin>>aim>>format;
int s=0,llen;
int ind=0;
while(llen=read(format,ind)){
char fch=aim[s];
int clen=0;
for(int j=0;j<llen;j++){
if(aim[j+s]==fch){
clen++;
}
else {
if(clen<11){
ans=ans+base[clen-1]+num[fch-'0'];
}
else {
while(clen--)ans=ans+num[fch-'0'];
}
clen=1;
}
fch=aim[s+j];
}
s+=llen;
if(clen<11){
ans+=base[clen-1]+num[fch-'0'];
}
else {
while(clen--)ans+=num[fch-'0'];
}
}
cout<<"Case "<<"#"<<ti<<":"<<ans<<endl;
}
return 0;
}

  C:

Rational Number Tree

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Consider an infinite complete binary tree where the root node is 1/1 and left and right childs of node p/q are p/(p+q) and (p+q)/q, respectively. This tree looks like:

         1/1
    ______|______
    |           |
   1/2         2/1
___|___     ___|___
|     |     |     |
1/3   3/2   2/3   3/1
...

It is known that every positive rational number appears exactly once in this tree. A level-order traversal of the tree results in the following array:

1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, ...

Please solve the following two questions:

  1. Find the n-th element of the array, where n starts from 1. For example, for the input 2, the correct output is 1/2.
  2. Given p/q, find its position in the array. As an example, the input 1/2 results in the output 2.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow. Each test case consists of one line.

The line contains a problem id (1 or 2) and one or two additional integers:

  1. If the problem id is 1, then only one integer n is given, and you are expected to find the n-th element of the array.
  2. If the problem id is 2, then two integers p and q are given, and you are expected to find the position of p/q in the array.

p and q are relatively prime.

1 ≤ n, p, q ≤ 264-1

p/q is an element in a tree with level number ≤ 64.

Output

For each test case:

  1. If the problem id is 1, then output one line containing "Case #x: p q", where x is the case number (starting from 1), and p, q are numerator and denominator of the asked array element, respectively.
  2. If the problem id is 2, then output one line containing "Case #x: n", where x is the case number (starting from 1), and n is the position of the given number.

Sample Input

4
1 2
2 1 2
1 5
2 3 2

Sample Output

Case #1: 1 2
Case #2: 2
Case #3: 3 2
Case #4: 5 应用时:15min
实际用时:62min
WWWWWWA
错误原因:
1:直接取反不相当于逆序
2:unsigned long long,恰取到64而不是在63内
3:unsigned long long 应当用%llu而不是%llud输出
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned long long ll;
int bit[66],blen;
ll n,p,q;
void divide(ll tn){
blen=0;
while(tn>0){
bit[blen++]=tn&1;
tn>>=1;
}
}
void calc1(){
p=1,q=1;
for(int i=blen-2;i>=0;i--){
if(bit[i]){
p=p+q;
}
else{
q=p+q;
}
}
}
void calc2(){
n=1;
blen=0;
while(p!=q){
if(p>q){
p-=q;
bit[blen++]=1;
}
else{
q-=p;
bit[blen++]=0;
}
}
for(int i=blen-1;i>=0;i--){
n<<=1;
n+=bit[i];
}
}
int main(){
int T;
scanf("%d",&T);
for(int ti=1;ti<=T;ti++){
int op;
blen=0;
memset(bit,0,sizeof(bit));
scanf("%d",&op);
if(op==1){
scanf("%llu",&n);
divide(n);
calc1();
printf("Case #%d: %llu %llu\n",ti,p,q);
}
else {
scanf("%llu%llu",&p,&q);
calc2();
printf("Case #%d: %llu\n",ti,n);
}
}
return 0;
}

  


快速切题 acdream手速赛(6)A-C的更多相关文章

  1. ACDream手速赛2

    地址:http://acdream.info/onecontest/1014   都是来自Codeforce上简单题.   A. Boy or Girl 简单字符串处理   B. Walking in ...

  2. Acdream手速赛7

    蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...

  3. ACdream区域赛指导赛之手速赛系列(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183        回到作案现场 ...

  4. ACdream区域赛指导赛之手速赛系列(5) 题解

    A - Problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submi ...

  5. ACdream区域赛指导赛之手速赛系列(7)

    A -Dragon Maze Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  6. Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)

    题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...

  7. 手速太慢QAQ

    显然D是个细节题,但是还剩1h时看眼榜还没人过EF,只好冷静写D,大概思路是任何时候如果min(n,m)<=2,max(n,m)<=4暴搜,否则直接贪心是很对的,即第一步让S.T长度平均化 ...

  8. TCP数据接收及快速路径和慢速路径

    概述 tcp握手完成后,收到数据包后,调用路径为tcp_v4_rcv->tcp_v4_do_rcv->tcp_rcv_established在tcp_rcv_established中处理T ...

  9. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

随机推荐

  1. 解决Type safety: The expression of type List needs

    解决Type safety: The expression of type List needs unchecked conversion to conform to 在方法前加上这句话就可以了@Su ...

  2. UVA 10462 Is There A Second Way Left?(次小生成树&Prim&Kruskal)题解

    思路: Prim: 这道题目中有重边 Prim可以先加一个sec数组来保存重边的次小边,这样不会影响到最小生成树,在算次小生成树时要同时判断次小边(不需判断是否在MST中) Kruskal: Krus ...

  3. Pc端css初始化

    @charset "UTF-8"; /**css初始化**/ body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd ...

  4. caffe深度学习网络(.prototxt)在线可视化工具:Netscope Editor

    http://ethereon.github.io/netscope/#/editor 网址:http://ethereon.github.io/netscope/#/editor 将.prototx ...

  5. axis2框架用wsdl文件生成的服务端MessageReceiveInOut文件注意事项

    在用axis2生成服务端文件和客户端文件,当客户端文件调用服务端文件时,都是通过wsdl文件生成的 配置文件进行相互的调用. 在一开始做开发测试的时候,通过soapUI进行调用接口的时候,可以调用成功 ...

  6. Mac OSX 安装qemu

    参考: Installing QEMU on OS X Homebrew Mac OSX 安装qemu 1.Install Homebrew: /usr/bin/ruby -e "$(cur ...

  7. POST提交大量数据,导致后面数据丢失

    这个问题,解决了很久,先简单说下我解决的具体思路: 首先:form表单提交,导致后面数据丢失,考虑了提交大量的数据,导致后台溢出,剩余数据量丢失,所以从网上搜了教程: 参考链接: https://bl ...

  8. 深蓝色 --ppt

    Deep Learning of Binary Hash Codes for Fast Image Retrieval [Paper] [Code-Caffe] 1. 摘要 针对图像检索问题,提出简单 ...

  9. Android本地广播

    Android中使用的广播一般是系统全局广播,即发出的广播可以被其他任何应用程序接收到,并且我们也可以接收来自于其他任何应用程序的广播.这样就很容易会引起安全性的问题,比如说我们发送的一些携带关键性数 ...

  10. bnu 51636 Squared Permutation 线段树

    Squared Permutation Time Limit: 6000ms Memory Limit: 262144KB 64-bit integer IO format: %lld      Ja ...